SQL SERVER 2008 – How does one count different data values in a column

Use this simple query to count the number of data values in a column:

select my_table_column, count(*)

from   my_table

group  by my_table_column;

A more sophisticated example…

select dept, sum(  decode(sex,’M’,1,0)) MALE,

sum(  decode(sex,’F’,1,0)) FEMALE,

count(decode(sex,’M’,1,’F’,1)) TOTAL

from   my_emp_table

group  by dept;

 

Reference : Dilip Kumar Jena ( https://sqlexplore.wordpress.com )

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s