一个group by语句
针对用户名分组,然后计算每个用户下a和b的个数(a,b属于同一列,数值不同),该如何写呢?
------解决方案--------------------假设a,b在的那列列名叫Number
select username,count(case Number when a then a end) as acount,
count(case Number when b then b end) as bcount
from table
group by username
------解决方案--------------------基础的分组求和
select c1,
sum(decode(c2,'a',1,0)) count_a,
sum(decode(c2,'b',1,0)) count_b
from tb1
group by c1