Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
theworm91
Starting Member
2 Posts |
Posted - 2005-04-18 : 11:59:59
|
| It's been awhile since I have created any queries. Could somebody please help me with a simple query. I have 3 columns in a table 2 are numeric and one is a datetime. I will call them col1 col2 and col3. Here is what I would like to do in one query. I want to do a group by on col3 and produce a count of the distinct numbers. For example if there are 10 row in this table and col3 has the number 10 in it 3 time I would like the query to have the output of 3 for the count. I hope this makes sense, please let me know if it doesn’tThanks |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2005-04-18 : 12:34:27
|
| [code]USE NorthwindGoSET NOCOUNT ONCREATE TABLE myTable99(Col1 datetime, Col2 int, Col3 int)GOINSERT INTO myTable99(Col1, Col2, Col3)SELECT '1/1/2005' , 1, 1 UNION ALLSELECT '1/21/2005', 2, 10 UNION ALLSELECT '2/14/2005', 3, 10 UNION ALLSELECT '3/17/2005', 4, 10 UNION ALLSELECT '4/1/2005' , 5, 15 UNION ALLSELECT '5/30/2005', 6, 15 UNION ALLSELECT '7/4/2005' , 7, 19 UNION ALLSELECT '9/5/2005' , 8, 20GO SELECT Col3, COUNT(*) AS Occurs FROM myTable99GROUP BY Col3GOSET NOCOUNT OFFDROP TABLE myTable99GO[/code]Brett8-) |
 |
|
|
theworm91
Starting Member
2 Posts |
Posted - 2005-04-18 : 12:45:51
|
| Thank you, I will work with that. |
 |
|
|
|
|
|
|
|