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 |
|
mike123
Master Smack Fu Yak Hacker
1462 Posts |
Posted - 2003-08-13 : 21:29:47
|
| I have a table with 50,000 records. In this table is a column called STATEID (1 - 65) (some provinces too).I want to have a query that comes up with the count of rows for each stateid. Do I have to write a query for each stateid ? ieselect count(userID) as '1' from tbluserdetails where stateprovid = '1' select count(userID) as '2' from tbluserdetails where stateprovid = '2' Or is there a better, simpler, faster way?Thanks for any helpMike123 |
|
|
chadmat
The Chadinator
1974 Posts |
Posted - 2003-08-13 : 21:35:13
|
| select StateProvID, count(*)from tbluserdetailsgroup by StateProvID-Chadhttp://www.clrsoft.comSoftware built for the Common Language Runtime. |
 |
|
|
SamC
White Water Yakist
3467 Posts |
Posted - 2003-08-13 : 21:46:01
|
| Chad has it right, but you might want to name the column with the count..SELECT StateProvID , count(*) as TotalFROM tbluserdetailsGROUP BY StateProvIDORDER BY StateProvID -- or you might ORDER BY TotalSam |
 |
|
|
mike123
Master Smack Fu Yak Hacker
1462 Posts |
Posted - 2003-08-15 : 04:56:00
|
| thanks alot guysalways a great helpmike123 |
 |
|
|
|
|
|