Friday, March 9, 2012

Help with query

Hi gurus, I have a table like this:
id, somethingelse
1 lala
1 lala1
1 lala2
1 lala3
2 lalala
2 lalalal
3 dfasdfsd
What I need to do is to count the amount of times a specific ID isrepeated (like a COUNT) and return the top 10 (distinctive) ids thatappear the most.
Any ideas?
You should be able to do it like this:
SELECT TOP 10
ID,
COUNT(*) AS IDCount
FROM
yourTable
GROUP BY
ID
ORDER BY
2 DESC

|||The GROUP BY was the key,
SELECT TOP 10 ID, COUNT(*) AS RepeatCount
FROM Employees
GROUP BY ID
ORDER BY RepeatCount DESC
Thanks!

No comments:

Post a Comment