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 |
|
sql777
Constraint Violating Yak Guru
314 Posts |
Posted - 2006-01-17 : 08:15:44
|
| Hi,I have a table with #'s in a column, these #'s may be repeat many times in the rows. I want to get a result set that has the most popular #'s listed in order.Table:ID Name Price1 abc 200002 aew 220003 was 200004 asw 150005 wek 220006 asdf 20000so I want a SELECT statement that will return:PRICE COUNT20000 322000 215000 1thanks in advance! |
|
|
ditch
Master Smack Fu Yak Hacker
1466 Posts |
Posted - 2006-01-17 : 08:18:25
|
SELECT Price, COUNT(1)FROM YourTableGROUP BY PriceORDER BY COUNT(1) DESCDuane. |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-01-17 : 08:19:56
|
Use GROUP BY to group it by PRICE and ORDER BY to sort it by descending orderselect PRICE, count(*) as [COUNT]from table1group by PRICEorder by [COUNT] desc -----------------'KH' |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-01-17 : 08:29:53
|
| Learn SQLhttp://www.sql-tutorial.net/ http://www.firstsql.com/tutor.htmMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|