日期:2014-05-17 浏览次数:21136 次
select classid,
count(*) "flag(总数)",
sum(decode(flag,'N',1,0)) "flag(N)",
sum(decode(flag,'Y',1,0)) "flag(Y)"
from table
group by classid
order by classid
select a.classid,
(select count(*) from tb b where b.classid = a.classid) "flag(总数)",
(select count(*) from tb c where c.classid = a.classid and c.flag = 'N') "flag(N)",
(select count(*) from tb d where d.classid = a.classid and c.flag = 'Y') "flag(Y)"
from tb a