示范:假定原有查询如下:
1、Select 部门,count(*) as 应该出勤人数 from a where col1 = 123
2、Select 部门,count(*) as 实际出勤人数 from a where col1 = 123 AND col2 = 'xxx'则如此实现:
Select 部门,
count(*) as 应该出勤人数,
sum(Decode(col2,'xxx',1,0)) as 实际出勤人数
sum(Decode(col2,'xxx',1,0))/count(*) as 出勤率
from a where col1 = 123
1、Select 部门,count(*) as 应该出勤人数 from a where col1 = 123
2、Select 部门,count(*) as 实际出勤人数 from a where col1 = 123 AND col2 = 'xxx'则如此实现:
Select 部门,
count(*) as 应该出勤人数,
sum(Decode(col2,'xxx',1,0)) as 实际出勤人数
sum(Decode(col2,'xxx',1,0))/count(*) as 出勤率
from a where col1 = 123
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货