select sum(case when(remark='Regular') then count(*)
when(remark='Half Day') then count(*)* 0.5
end),
shift
from attendance
where empid='1447' and mont='02' and payyear='2015'
group by shift, remark
order by shift
如何在SQL Server中编写?
答案 0 :(得分:2)
将案例放在聚合函数中:
select sum(case when remark = 'Regular' then 1
when remark = 'Half Day' then 0.5
end),
shift
from attendance
where empid='1447' and mont='02' and payyear='2015'
group by shift
order by shift
另外,从remark
删除group by
。