select b.busi_id,
(select count(*) from t_od_order o where o.order_status = '0' and o.busi_id = b.busi_id) 待启动,
(select count(*) from t_od_order o where o.order_status = '1' and o.busi_id = b.busi_id) 正在施工,
(select count(*) from t_od_order o where o.order_status = '2' and o.busi_id = b.busi_id) 已完成,
(select count(*) from t_od_order o where o.order_status = '4' and o.busi_id = b.busi_id) 已注销,
(select count(*) from t_od_order o where o.order_status = '5' and o.busi_id = b.busi_id) 已启动,
(select count(*) from t_od_order o where o.order_status = '8' and o.busi_id = b.busi_id) 正在注销,
(select count(*) from t_od_order o where o.order_status = 'A' and o.busi_id = b.busi_id) 待启动,
(select count(*) from t_od_order o where o.order_status = 'P' and o.busi_id = b.busi_id) 等待施工,
(select count(*) from t_od_order o where o.busi_id = b.busi_id) 总计,
b.busi_name
from t_od_business b
目的分别查出每种状态对应的总数

解决方案 »

  1.   


    select b.busi_id,  count(decode( o.order_status,'0', 1, null)) 待启动, 
                 count(decode( o.order_status, '1' , 1, null)) 正在施工,
                 count(decode( o.order_status, '2' , 1, null))  已完成,
                 count(decode( o.order_status, '4' , 1, null))  已注销,
                 count(decode( o.order_status,'5' , 1, null)) 已启动,
                 count(decode( o.order_status, '8' , 1, null))  正在注销,
                 count(decode( o.order_status, 'A', 1, null)) 待启动,
                 count(decode( o.order_status, 'P' , 1, null))  等待施工,
                 count(*) 总计
        from t_od_order o where  o.busi_id = b.busi_id
      group by b.busi_id
      order by b.busi_id