Home > Archive > MS SQL Server MSEQ > June 2005 > select most common value









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author select most common value
Leo

2005-06-28, 7:23 am

I am trying to create a list of the top 5 values in a column where I can
select which top value I want. For example with values
1,1,2,3,3,3
I can select the 2nd most common value (which is 1).
David Portas

2005-06-28, 8:24 pm

SELECT TOP 5 WITH TIES col
FROM YourTable
GROUP BY col
ORDER BY COUNT(*) DESC

--
David Portas
SQL Server MVP
--


Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2008 droptable.com