select org_name,'3',sum(decode(state_id,'3',1,0))
'4',sum(decode(state_id,'4',1,0))
'all',count(*) from tablename group by org_name
'4',sum(decode(state_id,'4',1,0))
'all',count(*) from tablename group by org_name
之前忘记了一个细节。就是 state_id 不只是有3和4这两种状态,还有其他的状态。
但是其他的状态是不需要记录在总数量中。
因为有别的状态 ,所以count(*)算出可能要比 state_id =3 和4的总和要多。。
这个要如何统计呢?
sum(decode(state_id,'3',1,0)) +sum(decode(state_id,'4',1,0)) 。。OMG。。