Badar
Badar

Reputation: 1460

How can I count a column with values

I have a column in sql table which contains 3 different values; ef: present, absent and leave. I want to count them with select and return different counts which reperesent them. How can I do this.

Upvotes: 0

Views: 54

Answers (1)

Horaciux
Horaciux

Reputation: 6477

select columnname, count(*)
from YourTable
group by columnName

or

select 
sum(case when columnname='present' then =1 end) 'present',
sum(case when columnname='absent' then =1 end) 'absent',
sum(case when columnname='leave' then =1 end) 'leave'
from myTable

Upvotes: 3

Related Questions