How do I get a list of unique values and the number of occurences from SQL Server 2008?
I have a SQL Server 2008 database with millions of records. One field has values ranging from 0 to 250 and may, or may not, include all numbers witin the range. How do I query the database to get a list of distinct values and the number of records contaiing that value?
I used a Select Cou开发者_如何学运维nt(Distinct) query but that only gives me the number of distinct values.
You want to use the GROUP BY clause:
SELECT
column1,
COUNT(*)
FROM
table
GROUP BY column1
精彩评论