Link to home
Start Free TrialLog in
Avatar of Member_2_1242703
Member_2_1242703

asked on

SELECT DISTINCT values and count of that value from SQL table

I need a query that selects distinct values from a column and then the total number of occurrences of that value in the table.

COL1

2008
2008
2008
2009
2009
2010
2010
2010
2010
2010
2011
2011
2012
2013
2013
2013
2013
2013
2013

Expected result would be

RESULT
=======
2008 (3)
2009 (2)
2010 (5)
2011 (2)
2012 (1)
2013 (6)
ASKER CERTIFIED SOLUTION
Avatar of ste5an
ste5an
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Kanti Prasad
Kanti Prasad

Hi

SELECT COL1, count(*) AS count
FROM TableName
WHERE COL1 is not null
GROUP BY COL1;