[selectRecords] select wk.keys , wk.tok_nm as tok_nm --, max(wk.tok_nm) as tok_nm , COALESCE(sum(wk.kingaku),0) as kingaku , COALESCE(sum(wk.genkin),0) as genkin , COALESCE(sum(wk.kogitte),0) as kogitte , COALESCE(sum(wk.furikomi),0) as furikomi , COALESCE(sum(wk.tesuryo),0) as tesuryo , COALESCE(sum(wk.tegata),0) as tegata , COALESCE(sum(wk.sousai),0) as sousai , COALESCE(sum(wk.sonota),0) as sonota , COALESCE(sum(wk.total_gaku),0) as total_gaku ,(case '&1' when '' then '' else to_char(to_date('&1', 'YYYYMMDD'),'YYYY/MM/DD') || '  〜' end) as ymd_start ,(case '&2' when '' then '' else to_char(to_date('&2', 'YYYYMMDD'),'YYYY/MM/DD') end) as ymd_end from ( --現金売上 select t.&7 as keys , case coalesce(t.tok_nm,'') when '' then coalesce(tk.tok_nm,'') else coalesce(t.tok_nm,'') end as tok_nm --, max(tk.tok_nm) as tok_nm , sum(t.nyukin_gaku) as kingaku , 0 as genkin , 0 as kogitte , 0 as furikomi , sum(t.tesuryo) as tesuryo , 0 as tegata , 0 as sousai , sum(t.cyosei_gaku) as sonota , sum(t.total_gaku) as total_gaku from t_nyukin t left join m_tokui tk on tk.tok_cd = t.tok_cd left join m_tanto tan on (tan.tan_cd = t.tan_cd) left join m_hanyo h13 on (h13.mst_kbn = '13' and h13.han_cd = t.nyukin_kbn) where 1 = 1 and t.del_flg = 0 -- and t.nyukin_kbn = '0' and h13.koumoku1 = 'genkin' and exists (select 1 from t_nyu_keshi nk inner join t_uri uh on (nk.uri_no = uh.den_no and uh.cash_flg = 1 and uh.del_flg = 0) where nk.nyukin_no = t.nyukin_no and nk.del_flg = 0) and (t.tok_cd >= '&3' or '' = '&3') and (t.tok_cd <= '&4' or '' = '&4') and (t.tan_cd >= '&5' or '' = '&5') and (t.tan_cd <= '&6' or '' = '&6') and (t.nyukin_ymd >= '&1' or '' = '&1') and (t.nyukin_ymd <= '&2' or '' = '&2') group by t.&7,tk.tok_nm,t.tok_nm, t.nyukin_kbn --入金(現金) union all select t.&7 as keys , case coalesce(t.tok_nm,'') when '' then coalesce(tk.tok_nm,'') else coalesce(t.tok_nm,'') end as tok_nm --, max(tk.tok_nm) as tok_nm , 0 as kingaku , sum(t.nyukin_gaku) as genkin , 0 as kogitte , 0 as furikomi , sum(t.tesuryo) as tesuryo , 0 as tegata , 0 as sousai , sum(t.cyosei_gaku) as sonota , sum(t.total_gaku) as total_gaku from t_nyukin t left join m_tokui tk on tk.tok_cd = t.tok_cd left join m_tanto tan on (tan.tan_cd = t.tan_cd) left join m_hanyo h13 on (h13.mst_kbn = '13' and h13.han_cd = t.nyukin_kbn) where 1 = 1 and t.del_flg = 0 -- and t.nyukin_kbn = '0' and h13.koumoku1 = 'genkin' and not exists (select 1 from t_nyu_keshi nk inner join t_uri uh on (nk.uri_no = uh.den_no and uh.cash_flg = 1 and uh.del_flg = 0) where nk.nyukin_no = t.nyukin_no and nk.del_flg = 0) and (t.tok_cd >= '&3' or '' = '&3') and (t.tok_cd <= '&4' or '' = '&4') and (t.tan_cd >= '&5' or '' = '&5') and (t.tan_cd <= '&6' or '' = '&6') and (t.nyukin_ymd >= '&1' or '' = '&1') and (t.nyukin_ymd <= '&2' or '' = '&2') group by t.&7,tk.tok_nm,t.tok_nm, t.nyukin_kbn --入金(小切手) union all select t.&7 as keys , case coalesce(t.tok_nm,'') when '' then coalesce(tk.tok_nm,'') else coalesce(t.tok_nm,'') end as tok_nm --, max(tk.tok_nm) as tok_nm , 0 as kingaku , 0 as genkin , sum(t.nyukin_gaku) as kogitte , 0 as furikomi , sum(t.tesuryo) as tesuryo , 0 as tegata , 0 as sousai , sum(t.cyosei_gaku) as sonota , sum(t.total_gaku) as total_gaku from t_nyukin t left join m_tokui tk on tk.tok_cd = t.tok_cd left join m_tanto tan on (tan.tan_cd = t.tan_cd) left join m_hanyo h13 on (h13.mst_kbn = '13' and h13.han_cd = t.nyukin_kbn) where 1 = 1 and t.del_flg = 0 -- and t.nyukin_kbn = '1' and h13.koumoku1 = 'kogitte' and (t.tok_cd >= '&3' or '' = '&3') and (t.tok_cd <= '&4' or '' = '&4') and (t.tan_cd >= '&5' or '' = '&5') and (t.tan_cd <= '&6' or '' = '&6') and (t.nyukin_ymd >= '&1' or '' = '&1') and (t.nyukin_ymd <= '&2' or '' = '&2') group by t.&7,tk.tok_nm,t.tok_nm, t.nyukin_kbn --入金(振込) union all select t.&7 as keys , case coalesce(t.tok_nm,'') when '' then coalesce(tk.tok_nm,'') else coalesce(t.tok_nm,'') end as tok_nm --, max(tk.tok_nm) as tok_nm , 0 as kingaku , 0 as genkin , 0 as kogitte , sum(t.nyukin_gaku) as furikomi , sum(t.tesuryo) as tesuryo , 0 as tegata , 0 as sousai , sum(t.cyosei_gaku) as sonota , sum(t.total_gaku) as total_gaku from t_nyukin t left join m_tokui tk on tk.tok_cd = t.tok_cd left join m_tanto tan on (tan.tan_cd = t.tan_cd) left join m_hanyo h13 on (h13.mst_kbn = '13' and h13.han_cd = t.nyukin_kbn) where 1 = 1 and t.del_flg = 0 -- and t.nyukin_kbn = '2' and h13.koumoku1 = 'furikomi' and (t.tok_cd >= '&3' or '' = '&3') and (t.tok_cd <= '&4' or '' = '&4') and (t.tan_cd >= '&5' or '' = '&5') and (t.tan_cd <= '&6' or '' = '&6') and (t.nyukin_ymd >= '&1' or '' = '&1') and (t.nyukin_ymd <= '&2' or '' = '&2') group by t.&7,tk.tok_nm,t.tok_nm, t.nyukin_kbn --振込手数料 union all select t.&7 as keys , case coalesce(t.tok_nm,'') when '' then coalesce(tk.tok_nm,'') else coalesce(t.tok_nm,'') end as tok_nm --, max(tk.tok_nm) as tok_nm , 0 as kingaku , 0 as genkin , 0 as kogitte , 0 as furikomi , sum(t.total_gaku) as tesuryo , 0 as tegata , 0 as sousai , 0 as sonota , sum(t.total_gaku) as total_gaku from t_nyukin t left join m_tokui tk on tk.tok_cd = t.tok_cd left join m_tanto tan on (tan.tan_cd = t.tan_cd) left join m_hanyo h13 on (h13.mst_kbn = '13' and h13.han_cd = t.nyukin_kbn) where 1 = 1 and t.del_flg = 0 -- and t.nyukin_kbn = '3' and h13.koumoku1 = 'tesuryo' and (t.tok_cd >= '&3' or '' = '&3') and (t.tok_cd <= '&4' or '' = '&4') and (t.tan_cd >= '&5' or '' = '&5') and (t.tan_cd <= '&6' or '' = '&6') and (t.nyukin_ymd >= '&1' or '' = '&1') and (t.nyukin_ymd <= '&2' or '' = '&2') group by t.&7,tk.tok_nm,t.tok_nm, t.nyukin_kbn --入金(手形) union all select t.&7 as keys , case coalesce(t.tok_nm,'') when '' then coalesce(tk.tok_nm,'') else coalesce(t.tok_nm,'') end as tok_nm --, max(tk.tok_nm) as tok_nm , 0 as kingaku , 0 as genkin , 0 as kogitte , 0 as furikomi , sum(t.tesuryo) as tesuryo , sum(t.nyukin_gaku) as tegata , 0 as sousai , sum(t.cyosei_gaku) as sonota , sum(t.total_gaku) as total_gaku from t_nyukin t left join m_tokui tk on tk.tok_cd = t.tok_cd left join m_tanto tan on (tan.tan_cd = t.tan_cd) left join m_hanyo h13 on (h13.mst_kbn = '13' and h13.han_cd = t.nyukin_kbn) where 1 = 1 and t.del_flg = 0 -- and t.nyukin_kbn = '4' and h13.koumoku1 = 'tegata' and (t.tok_cd >= '&3' or '' = '&3') and (t.tok_cd <= '&4' or '' = '&4') and (t.tan_cd >= '&5' or '' = '&5') and (t.tan_cd <= '&6' or '' = '&6') and (t.nyukin_ymd >= '&1' or '' = '&1') and (t.nyukin_ymd <= '&2' or '' = '&2') group by t.&7,tk.tok_nm,t.tok_nm, t.nyukin_kbn --相殺 union all select t.&7 as keys , case coalesce(t.tok_nm,'') when '' then coalesce(tk.tok_nm,'') else coalesce(t.tok_nm,'') end as tok_nm --, max(tk.tok_nm) as tok_nm , 0 as kingaku , 0 as genkin , 0 as kogitte , 0 as furikomi , sum(t.tesuryo) as tesuryo , 0 as tegata , sum(t.nyukin_gaku) as sousai , sum(t.cyosei_gaku) as sonota , sum(t.total_gaku) as total_gaku from t_nyukin t left join m_tokui tk on tk.tok_cd = t.tok_cd left join m_tanto tan on (tan.tan_cd = t.tan_cd) left join m_hanyo h13 on (h13.mst_kbn = '13' and h13.han_cd = t.nyukin_kbn) where 1 = 1 and t.del_flg = 0 -- and t.nyukin_kbn = '5' and h13.koumoku1 = 'sousai' and (t.tok_cd >= '&3' or '' = '&3') and (t.tok_cd <= '&4' or '' = '&4') and (t.tan_cd >= '&5' or '' = '&5') and (t.tan_cd <= '&6' or '' = '&6') and (t.nyukin_ymd >= '&1' or '' = '&1') and (t.nyukin_ymd <= '&2' or '' = '&2') group by t.&7,tk.tok_nm,t.tok_nm, t.nyukin_kbn --その他 union all select t.&7 as keys , case coalesce(t.tok_nm,'') when '' then coalesce(tk.tok_nm,'') else coalesce(t.tok_nm,'') end as tok_nm --, max(tk.tok_nm) as tok_nm , 0 as kingaku , 0 as genkin , 0 as kogitte , 0 as furikomi , 0 as tesuryo , 0 as tegata , 0 as sousai , sum(t.total_gaku) as sonota , sum(t.total_gaku) as total_gaku from t_nyukin t left join m_tokui tk on tk.tok_cd = t.tok_cd left join m_tanto tan on (tan.tan_cd = t.tan_cd) left join m_hanyo h13 on (h13.mst_kbn = '13' and h13.han_cd = t.nyukin_kbn) where 1 = 1 and t.del_flg = 0 -- and t.nyukin_kbn = '9' and COALESCE(h13.koumoku1,'') = '' and (t.tok_cd >= '&3' or '' = '&3') and (t.tok_cd <= '&4' or '' = '&4') and (t.tan_cd >= '&5' or '' = '&5') and (t.tan_cd <= '&6' or '' = '&6') and (t.nyukin_ymd >= '&1' or '' = '&1') and (t.nyukin_ymd <= '&2' or '' = '&2') group by t.&7,tk.tok_nm,t.tok_nm, t.nyukin_kbn ) wk where 1=1 group by wk.keys, wk.tok_nm order by wk.keys ;