首先建表
t13
create t13 as (select rpt_id,chk_ind,rs_flag_id from rpt_ind group by rpt_id)
t14
create "这里是表名我这是t14" as (select a.rpt_id,num1 from (select rpt_id,count(rpt_id) num1 from t13 group by rpt_id)a,(select rpt_id,count(rpt_id) from t13 where rs_flag_id !='1' group by rpt_id)b where a.rpt_id=b.rpt_id GROUP BY a.rpt_id,num1)
select a.num as "检查数",r1 as "总人数",r2 as "异常人数" from
(with bigTable AS (select rpt_id,cast(count(*) as varchar(10)) num from t13 group by rpt_id)
select
num,
case num
when '1' then (select count(*) from bigTable where num ='1' group by num)
when '2' then (select count(*) from bigTable where num ='2' group by num)
when '3' then (select count(*) from bigTable where num ='3' group by num)
when '4' then (select count(*) from bigTable where num ='4' group by num)
when '5' then (select count(*) from bigTable where num ='5' group by num)
when '6' then (select count(*) from bigTable where num ='6' group by num)
when '7' then (select count(*) from bigTable where num ='7' group by num)
when '8' then (select count(*) from bigTable where num ='8' group by num)
when '9' then (select count(*) from bigTable where num ='9' group by num)
end as r1
from bigTable GROUP BY num)a left outer join
(with bigTable AS (select rpt_id, cast(num1 as varchar(10))num from t14) select num, case num when '1' then (select count(*) from bigTable where num ='1' group by num) when '2' then (select count(*) from bigTable where num ='2' group by num) when '3' then (select count(*) from bigTable where num ='3' group by num) when '4' then (select count(*) from bigTable where num ='4' group by num) when '5' then (select count(*) from bigTable where num ='5' group by num) when '6' then (select count(*) from bigTable where num ='6' group by num) when '7' then (select count(*) from bigTable where num ='7' group by num) when '8' then (select count(*) from bigTable where num ='8' group by num) when '9' then (select count(*) from bigTable where num ='9' group by num) end as r2 from bigTable GROUP BY num)b
on a.num=b.num