[selectRecords] select kbn ,c2kbn ,cd2 ,han2 ,cd1 ,tan_nm ,suryo ,kingaku ,genka ,arari ,ritu ,case ('&16') when '' then '未指定' else to_char(to_date('&16', 'YYYYMMDD'), 'yyyy/mm/dd') end as dt_fr ,case ('&17') when '' then '未指定' else to_char(to_date('&17', 'YYYYMMDD'), 'yyyy/mm/dd') end as dt_to from (select 1 as kbn ,1 as c2kbn ,coalesce(tn.bu_cd,'') as cd2 ,'('||coalesce(tn.bu_cd,'')||')'||coalesce(hn3.han_name,'') as han2 ,coalesce(tn.tan_cd,'') as cd1 ,tn.tan_nm ,sum(coalesce(um.suryo,0)) as suryo ,sum(coalesce(um.zeinuki_gaku,0)) as kingaku ,sum(coalesce(um.genka_gaku,0)) as genka ,sum(coalesce(um.zeinuki_gaku,0))-sum(coalesce(um.genka_gaku,0)) as arari ,case (sum(coalesce(um.zeinuki_gaku,0))) when 0 then 0 else round((sum(coalesce(um.zeinuki_gaku,0))-sum(coalesce(um.genka_gaku,0)))*100/(sum(coalesce(um.zeinuki_gaku,0))),1) end as ritu ,case ('&16') when '' then '未指定' else to_char(to_date('&16', 'YYYYMMDD'), 'yyyy/mm/dd') end as dt_fr ,case ('&17') when '' then '未指定' else to_char(to_date('&17', 'YYYYMMDD'), 'yyyy/mm/dd') end as dt_to from t_uri t left join t_uri_m um on (um.den_no = t.den_no) left join m_hin hi on (hi.hin_cd = um.hin_cd) left join m_hanyo hn1 on (hn1.mst_kbn = '05' and hn1.han_cd = hi.cat_cd) left join m_hanyo hn2 on (hn2.mst_kbn = '14' and hn2.han_cd = hn1.koumoku1) left join m_tokui tk on (tk.tok_cd = t.tok_cd) --left join m_tanto tn on (tn.tan_cd = t.tan_cd) --left join m_tanto tn on (tn.tan_cd = t.eigyou_tan_cd) --2018.12.01 #6389 MOD STT --left join m_tanto tn on (tn.tan_cd = tk.tan_cd) left join m_tanto tn on (tn.tan_cd = (case when('&31' = 'tan_cd')then(t.tan_cd)else(tk.tan_cd)end)) --2018.12.01 #6389 MOD END left join m_hanyo hn3 on (hn3.mst_kbn = '55' and hn3.han_cd = tn.bu_cd) left join m_hanyo h01 on (h01.mst_kbn = '01' and h01.han_cd = t.prc_sts) where 1 = 1 and t.jucyu_flg = 0 and t.del_flg = 0 --and hi.del_flg = 0 and coalesce(h01.koumoku3, '') = '' and (('' = '&16') or (t.syori_ymd >= '&16')) and (('' = '&17') or (t.syori_ymd <= '&17')) and (('' = '&2') or (tn.bu_cd = '&2')) and (('' = '&24') or (tn.tan_cd >= '&24')) and (('' = '&25') or (tn.tan_cd <= '&25')) group by tn.bu_cd,hn3.han_name,tn.tan_cd,tn.tan_nm union all select 1 as kbn ,2 as c2kbn ,coalesce(tn.bu_cd,'') as cd2 ,'('||coalesce(tn.bu_cd,'')||')'||coalesce(hn3.han_name,'') as han2 ,'' as cd1 ,'部署合計' as tan_nm ,sum(coalesce(um.suryo,0)) as suryo ,sum(coalesce(um.zeinuki_gaku,0)) as kingaku ,sum(coalesce(um.genka_gaku,0)) as genka ,sum(coalesce(um.zeinuki_gaku,0))-sum(coalesce(um.genka_gaku,0)) as arari ,case (sum(coalesce(um.zeinuki_gaku,0))) when 0 then 0 else round((sum(coalesce(um.zeinuki_gaku,0))-sum(coalesce(um.genka_gaku,0)))*100/(sum(coalesce(um.zeinuki_gaku,0))),1) end as ritu ,case ('&16') when '' then '未指定' else to_char(to_date('&16', 'YYYYMMDD'), 'yyyy/mm/dd') end as dt_fr ,case ('&17') when '' then '未指定' else to_char(to_date('&17', 'YYYYMMDD'), 'yyyy/mm/dd') end as dt_to from t_uri t left join t_uri_m um on (um.den_no = t.den_no) left join m_hin hi on (hi.hin_cd = um.hin_cd ) left join m_hanyo hn1 on (hn1.mst_kbn = '05' and hn1.han_cd = hi.cat_cd) left join m_hanyo hn2 on (hn2.mst_kbn = '14' and hn2.han_cd = hn1.koumoku1) left join m_tokui tk on (tk.tok_cd = t.tok_cd) --left join m_tanto tn on (tn.tan_cd = t.tan_cd) --left join m_tanto tn on (tn.tan_cd = t.eigyou_tan_cd) --2018.12.01 #6389 MOD STT --left join m_tanto tn on (tn.tan_cd = tk.tan_cd) left join m_tanto tn on (tn.tan_cd = (case when('&31' = 'tan_cd')then(t.tan_cd)else(tk.tan_cd)end)) --2018.12.01 #6389 MOD END left join m_hanyo hn3 on (hn3.mst_kbn = '55' and hn3.han_cd = tn.bu_cd) left join m_hanyo h01 on (h01.mst_kbn = '01' and h01.han_cd = t.prc_sts) where 1 = 1 and t.jucyu_flg = 0 and t.del_flg = 0 --and hi.del_flg = 0 and coalesce(h01.koumoku3, '') = '' and (('' = '&16') or (t.syori_ymd >= '&16')) and (('' = '&17') or (t.syori_ymd <= '&17')) and (('' = '&2') or (tn.bu_cd = '&2')) and (('' = '&24') or (t.tan_cd >= '&24')) and (('' = '&25') or (t.tan_cd <= '&25')) group by tn.bu_cd,hn3.han_name union all select 2 as kbn ,null as c2kbn ,null as cd2 ,'' as han2 ,'' as cd1 ,'全部門合計' as tan_nm ,sum(coalesce(um.suryo,0)) as suryo ,sum(coalesce(um.zeinuki_gaku,0)) as kingaku ,sum(coalesce(um.genka_gaku,0)) as genka ,sum(coalesce(um.zeinuki_gaku,0))-sum(coalesce(um.genka_gaku,0)) as arari ,case (sum(coalesce(um.zeinuki_gaku,0))) when 0 then 0 else round((sum(coalesce(um.zeinuki_gaku,0))-sum(coalesce(um.genka_gaku,0)))*100/(sum(coalesce(um.zeinuki_gaku,0))),1) end as ritu ,case ('&16') when '' then '未指定' else to_char(to_date('&16', 'YYYYMMDD'), 'yyyy/mm/dd') end as dt_fr ,case ('&17') when '' then '未指定' else to_char(to_date('&17', 'YYYYMMDD'), 'yyyy/mm/dd') end as dt_to from t_uri t left join t_uri_m um on (um.den_no = t.den_no) left join m_hin hi on (hi.hin_cd = um.hin_cd ) left join m_hanyo hn1 on (hn1.mst_kbn = '05' and hn1.han_cd = hi.cat_cd) left join m_hanyo hn2 on (hn2.mst_kbn = '14' and hn2.han_cd = hn1.koumoku1) left join m_tokui tk on (tk.tok_cd = t.tok_cd) --left join m_tanto tn on (tn.tan_cd = t.tan_cd) --left join m_tanto tn on (tn.tan_cd = t.eigyou_tan_cd) --2018.12.01 #6389 MOD STT --left join m_tanto tn on (tn.tan_cd = tk.tan_cd) left join m_tanto tn on (tn.tan_cd = (case when('&31' = 'tan_cd')then(t.tan_cd)else(tk.tan_cd)end)) --2018.12.01 #6389 MOD END left join m_hanyo hn3 on (hn3.mst_kbn = '55' and hn3.han_cd = tn.bu_cd) left join m_hanyo h01 on (h01.mst_kbn = '01' and h01.han_cd = t.prc_sts) where 1 = 1 and t.jucyu_flg = 0 and t.del_flg = 0 --and hi.del_flg = 0 and coalesce(h01.koumoku3, '') = '' and (('' = '&16') or (t.syori_ymd >= '&16')) and (('' = '&17') or (t.syori_ymd <= '&17')) and (('' = '&2') or (tn.bu_cd = '&2')) and (('' = '&24') or (t.tan_cd >= '&24')) and (('' = '&25') or (t.tan_cd <= '&25')) ) s1 order by s1.kbn,s1.cd2,s1.c2kbn [selectGraph] select tn.tan_cd ,tn.tan_nm ,sum(coalesce(um.zeinuki_gaku,0))-sum((case when(&31 = 1)then(coalesce(um.genka_gaku,0))else(0)end)) as kingaku from t_uri t left join t_uri_m um on (um.den_no = t.den_no) left join m_hin hi on (hi.hin_cd = um.hin_cd and hi.del_flg = 0) left join m_hanyo hn1 on (hn1.mst_kbn = '05' and hn1.han_cd = hi.cat_cd) left join m_hanyo hn2 on (hn2.mst_kbn = '14' and hn2.han_cd = hn1.koumoku1) left join m_tokui tk on (tk.tok_cd = t.tok_cd) --left join m_tanto tn on (tn.tan_cd = t.eigyou_tan_cd) --2018.12.01 #6389 MOD STT --left join m_tanto tn on (tn.tan_cd = tk.tan_cd) left join m_tanto tn on (tn.tan_cd = (case when('&32' = 'tan_cd')then(t.tan_cd)else(tk.tan_cd)end)) --2018.12.01 #6389 MOD END left join m_hanyo hn3 on (hn3.mst_kbn = '55' and hn3.han_cd = tn.bu_cd) left join m_hanyo h01 on (h01.mst_kbn = '01' and h01.han_cd = t.prc_sts) where 1 = 1 and t.jucyu_flg = 0 and t.del_flg = 0 and coalesce(h01.koumoku3, '') = '' and (('' = '&16') or (t.syori_ymd >= '&16')) and (('' = '&17') or (t.syori_ymd <= '&17')) and (('' = '&2') or (tn.bu_cd = '&2')) and (('' = '&24') or (t.tan_cd >= '&24')) and (('' = '&25') or (t.tan_cd <= '&25')) group by tn.tan_cd, tn.tan_nm order by kingaku DESC limit 5