Get frequency of a column in SQL Server Get frequency of a column in SQL Server sql-server sql-server

Get frequency of a column in SQL Server


Use aggregate functions

 Select column, count(*) From   table Group By column

This will return one row that contains the count, for each distinct value in column


One row each value:

select column 'value', count (column) 'Frequency'from tablegroup by column

if only 2 values this give you both results in one row

select sum(case when column=1 then 1 else 0 end) as '1 Frequency',        sum(case when column=2 then 1 else 0 end) as '2 Frequency'from table