Sql语句可以这样:
select corp_ID,sum(case is_punish when 0 then 1 end ) as 奖励次数,
sum(case is_punish when 1 then 1 end) as 处罚次数 from table1
group by corp_ID
不知道oracle可否
select corp_ID,sum(case is_punish when 0 then 1 end ) as 奖励次数,
sum(case is_punish when 1 then 1 end) as 处罚次数 from table1
group by corp_ID
不知道oracle可否
sum(sum(decode(is_punish,0,1,0)) as '处罚次数' from A
group by corp_ID
select corp_ID,sum(decode(is_punish,0,1,0) as '奖励次数',
sum(decode(is_punish,1,1,0)) as '处罚次数' from A
group by corp_ID
a.corp_id 公司id,
sum(decode(a.is_punish,0,1,0)) 奖励次数,
sum(decode(a.is_punish,1,1,0)) 惩罚次数
from
tablea a
group by a.corp_id
select
corp_id 公司id,
sum(is_punish) 奖励次数,
sum(1-is_punish) 惩罚次数
from
tableA
group by corp_id
1 1 2 27-7月-04
2 1 0 25-7月-04这个记录时间是不管它受惩罚还是奖励的,那又如何写呢?
sum(decode(a.is_punish,0,1,0)) 奖励次数,
sum(decode(a.is_punish,1,1,0)) 惩罚次数,
max(rec_time) 最后记录时间
from tablea a
group by a.corp_id