Sql 如何计算具有值的列

Sql 如何计算具有值的列,sql,Sql,我在sql表中有一列,其中包含3个不同的值;ef:出席、缺席和离开。我想用select对它们进行计数,并返回重新呈现它们的不同计数。我怎样才能做到这一点 select columnname, count(*) from YourTable group by columnName 或 或 或 或 谢谢,我的select语句是:从sms.dbo.emp_attention中选择count(*),其中username='admin'和attention='present'分组依据attendance

我在sql表中有一列,其中包含3个不同的值;ef:出席、缺席和离开。我想用select对它们进行计数,并返回重新呈现它们的不同计数。我怎样才能做到这一点

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


谢谢,我的select语句是:从sms.dbo.emp_attention中选择count(*),其中username='admin'和attention='present'分组依据attendance@Badar由于您是按出勤率分组的,您可能希望将其作为列添加到select语句中,或删除多余的group by。谢谢,我的select语句是:select count(*)来自sms.dbo.emp_Attention,其中用户名='admin'和Attention='present'分组依据attendance@Badar由于您是按出勤率分组的,您可能希望将其作为列添加到select语句中,或删除多余的group by。谢谢,我的select语句是:select count(*)来自sms.dbo.emp_Attention,其中用户名='admin'和Attention='present'分组依据attendance@Badar由于您是按出勤率分组的,您可能希望将其作为列添加到select语句中,或删除多余的group by。谢谢,我的select语句是:select count(*)来自sms.dbo.emp_Attention,其中用户名='admin'和Attention='present'分组依据attendance@Badar由于您是按出勤率分组的,您可能希望将其作为列添加到select语句中,或者删除多余的group by。
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