统计报表的sql

统计报表sql

select t2.checkunit_uuid,
       t2.checkunit_zone,
       count(t.uuid) as atotal,
       sum(decode(t.get_card_status, 1, 1, 0)) as getTocal,
       sum(decode(t.get_card_status, null, 1, 0))as  noGetTocal,
      to_char( round(sum(decode(t.get_card_status, 1, 1, 0))/count(t.uuid)*100,10),'fm990.00')||'%' as comp
  from examineedetail t, examineedate t2
 where t.uuid = t2.detail_uuid
   and t.credential_code is not null
   and t.plan_uuid = 'cbaa6d10-68a6-4ac2-8932-dd87c00f16fd'
   and t2.checkunit_uuid = '6063e9d1-c2c3-41ab-b349-574a17098e4c'
 group by rollup( t2.checkunit_zone,t2.checkunit_uuid) having grouping(t2.checkunit_uuid) = '0' or (grouping(t2.checkunit_uuid) = '1' and grouping(t2.checkunit_zone) = '1' )
 select
        t2.checkunit_uuid as checkId,
        t2.checkunit_zone as checkZone,
        count(t.uuid) as atotal,
        sum(decode(t.get_card_status,
        1,
        1,
        0)) as getTocal,
        sum(decode(t.get_card_status,
        null,
        1,
        0))as  noGetTocal,
        to_char( round(sum(decode(t.get_card_status,
        1,
        1,
        0))/count(t.uuid)*100,
        10),
        'fm990.00')||'%' as comp  
    from
        examineedetail t,
        examineedate t2  
    where
        t.uuid = t2.detail_uuid  
        and t.credential_code is not null  
        and t.plan_uuid='cbaa6d10-68a6-4ac2-8932-dd87c00f16fd'  
    group  by
        rollup((t2.checkunit_uuid,
        t2.checkunit_zone))



 兄弟帮忙给写的,学习下

猜你喜欢

转载自liuna718-163-com.iteye.com/blog/2101310