一个表Test有a,b,c,d,e字段组成,我想通过一次遍历,把表中c字段的值求2个和,一个是满足
d='0' and e='0'条件的情况下,求一个和,一个是对字段求和,没有条件限制,最后分组,但是
有错误存在,请大家看看,如何能实现我的功能,该怎样修改。
select
a,
b,
case when d='0' and e='0' then sum(c) end as PP
sum(c),
from Test
group by
a,
b
d='0' and e='0'条件的情况下,求一个和,一个是对字段求和,没有条件限制,最后分组,但是
有错误存在,请大家看看,如何能实现我的功能,该怎样修改。
select
a,
b,
case when d='0' and e='0' then sum(c) end as PP
sum(c),
from Test
group by
a,
b
a,
b,
sum(case when d='0' and e='0' then c else 0 end) as PP
sum(c),
from Test
group by
a,
b