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 |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2002-03-24 : 18:10:07
|
| Thomas writes "I have a table of alarms.I want a list of the number of occurrences of each type of alarm ordered by the number of occurrences. Currently I:set r = db.OpenRecordset("SELECT distinct(atxt) FROM alarms")Do While Not r.EOF set r2 = db.openrecordset("select count(*) as nrecs from alarms where atxt='" & r.Fields("atxt") & "'") r.movenextloopThis returns all the records and their number of occurrences but it now needs to be sorted in order of number of occurrences of each.Is there a better way?Thanks for helpTom Ryan" |
|
|
Merkin
Funky Drop Bear Fearing SQL Dude!
4970 Posts |
Posted - 2002-03-24 : 18:55:34
|
Hi TomYes, there is a much easier and quicker way.Select atxt, count(*) as nrecsFROM alarmsGROUP BY atxtORDER BY count(*) DESC Hope that helpsDamian |
 |
|
|
|
|
|