[SelectRecords] select t2.CALENDAR ,sum(t2.WEIGHT_WP_A) as WEIGHT_WP_A ,sum(t2.SUMWEIGHT_WP_A) as SUMWEIGHT_WP_A ,sum(t2.MONEY_WP_A) as MONEY_WP_A ,sum(t2.SUMMONEY_WP_A) as SUMMONEY_WP_A ,sum(t2.WEIGHT_WP_B) as WEIGHT_WP_B ,sum(t2.SUMWEIGHT_WP_B) as SUMWEIGHT_WP_B ,sum(t2.MONEY_WP_B) as MONEY_WP_B ,sum(t2.SUMMONEY_WP_B) as SUMMONEY_WP_B ,sum(t2.WEIGHT_WP_C) as WEIGHT_WP_C ,sum(t2.SUMWEIGHT_WP_C) as SUMWEIGHT_WP_C ,sum(t2.MONEY_WP_C) as MONEY_WP_C ,sum(t2.SUMMONEY_WP_C) as SUMMONEY_WP_C ,sum(t2.WEIGHT_WP_A) + sum(t2.WEIGHT_WP_B) + sum(t2.WEIGHT_WP_C) as WEIGHT_WP_ALL ,sum(t2.SUMWEIGHT_WP_A) + sum(t2.SUMWEIGHT_WP_B) + sum(t2.SUMWEIGHT_WP_C) as SUMWEIGHT_WP_ALL ,sum(t2.MONEY_WP_A) + sum(t2.MONEY_WP_B) + sum(t2.MONEY_WP_C) as MONEY_WP_ALL ,sum(t2.SUMMONEY_WP_A) + sum(t2.SUMMONEY_WP_B) + sum(t2.SUMMONEY_WP_C) as SUMMONEY_WP_ALL ,t4.FREIGHT_A as FREIGHT_A ,t4.FREIGHT_B as FREIGHT_B ,t4.FREIGHT_C as FREIGHT_C ,t4.FREIGHT_A + t4.FREIGHT_B + t4.FREIGHT_C as FREIGHT_ALL ,t6.ADJUST_A as ADJUST_A ,t6.ADJUST_B as ADJUST_B ,t6.ADJUST_C as ADJUST_C ,t6.ADJUST_A + t6.ADJUST_B + t6.ADJUST_C as ADJUST_ALL ,t4.FREIGHT_A_weigth as FREIGHT_A_weigth ,t4.FREIGHT_B_weigth as FREIGHT_B_weigth ,t4.FREIGHT_C_weigth as FREIGHT_C_weigth ,t4.FREIGHT_A_weigth + t4.FREIGHT_B_weigth + t4.FREIGHT_C_weigth as FREIGHT_ALL_weigth ,t6.ADJUST_A_weigth as ADJUST_A_weigth ,t6.ADJUST_B_weigth as ADJUST_B_weigth ,t6.ADJUST_C_weigth as ADJUST_C_weigth ,t6.ADJUST_A_weigth + t6.ADJUST_B_weigth + t6.ADJUST_C_weigth as ADJUST_ALL_weigth FROM( select t1.CALENDAR ,sum(t1.WEIGHT_WP_A) as WEIGHT_WP_A ,t1.SUMWEIGHT_WP_A as SUMWEIGHT_WP_A ,sum(t1.MONEY_WP_A) as MONEY_WP_A ,t1.SUMMONEY_WP_A as SUMMONEY_WP_A ,sum(t1.WEIGHT_WP_B) as WEIGHT_WP_B ,t1.SUMWEIGHT_WP_B as SUMWEIGHT_WP_B ,sum(t1.MONEY_WP_B) as MONEY_WP_B ,t1.SUMMONEY_WP_B as SUMMONEY_WP_B ,sum(t1.WEIGHT_WP_C) as WEIGHT_WP_C ,t1.SUMWEIGHT_WP_C as SUMWEIGHT_WP_C ,sum(t1.MONEY_WP_C) as MONEY_WP_C ,t1.SUMMONEY_WP_C as SUMMONEY_WP_C from ( select mc.CALENDAR CALENDAR ,tw.WEIGHT_WP WEIGHT_WP_A ,(tw.MONEY_WP - tw.MONEY_WP_NO_FREIGHT) MONEY_WP_A ,(select sum(tw2.WEIGHT_WP) from T_RECEIVE_WP tw2 where tw2.DT_RECEIVESLIP >= to_date('&1' || '01', 'yyyymmdd') and tw2.DT_RECEIVESLIP <= mc.CALENDAR and tw2.CD_GRADE = 1 and tw2.CD_WP <> '999' and tw2.CD_WP <> '998' and tw2.FLG_DELETE = 0 ) as sumWEIGHT_WP_A ,(select sum(tw2.MONEY_WP - tw2.MONEY_WP_NO_FREIGHT) from T_RECEIVE_WP tw2 where tw2.DT_RECEIVESLIP >= to_date('&1' || '01', 'yyyymmdd') and tw2.DT_RECEIVESLIP <= mc.CALENDAR and tw2.CD_GRADE = 1 and tw2.CD_WP <> '999' and tw2.CD_WP <> '998' and tw2.FLG_DELETE = 0 ) as sumMONEY_WP_A ,0 WEIGHT_WP_B ,0 MONEY_WP_B ,0 sumWEIGHT_WP_B ,0 sumMONEY_WP_B ,0 WEIGHT_WP_C ,0 MONEY_WP_C ,0 sumWEIGHT_WP_C ,0 sumMONEY_WP_C from M_CALENDAR mc left join T_RECEIVE_WP tw on tw.DT_RECEIVESLIP = mc.CALENDAR and tw.CD_GRADE = 1 and tw.FLG_DELETE = 0 and tw.CD_WP <> '999' and tw.CD_WP <> '998' where mc.CALENDAR >= to_date('&1'||'01','yyyymmdd') and mc.CALENDAR < to_date('&2'||'01','yyyymmdd') union all select mc.CALENDAR CALENDAR ,0 WEIGHT_WP_A ,0 MONEY_WP_A ,0 sumWEIGHT_WP_A ,0 sumMONEY_WP_A ,tw.WEIGHT_WP WEIGHT_WP_B ,(tw.MONEY_WP - tw.MONEY_WP_NO_FREIGHT) MONEY_WP_B ,(select sum(tw2.WEIGHT_WP) from T_RECEIVE_WP tw2 where tw2.DT_RECEIVESLIP >= to_date('&1' || '01', 'yyyymmdd') and tw2.DT_RECEIVESLIP <= mc.CALENDAR and tw2.CD_GRADE = 2 and tw2.CD_WP <> '999' and tw2.CD_WP <> '998' and tw2.FLG_DELETE = 0 ) as sumWEIGHT_WP_B ,(select sum(tw2.MONEY_WP - tw2.MONEY_WP_NO_FREIGHT) from T_RECEIVE_WP tw2 where tw2.DT_RECEIVESLIP >= to_date('&1' || '01', 'yyyymmdd') and tw2.DT_RECEIVESLIP <= mc.CALENDAR and tw2.CD_GRADE = 2 and tw2.CD_WP <> '999' and tw2.CD_WP <> '998' and tw2.FLG_DELETE = 0 ) as sumMONEY_WP_B ,0 WEIGHT_WP_C ,0 MONEY_WP_C ,0 sumWEIGHT_WP_C ,0 sumMONEY_WP_C from M_CALENDAR mc left join T_RECEIVE_WP tw on tw.DT_RECEIVESLIP = mc.CALENDAR and tw.CD_GRADE = 2 and tw.FLG_DELETE = 0 and tw.CD_WP <> '999' and tw.CD_WP <> '998' where mc.CALENDAR >= to_date('&1'||'01','yyyymmdd') and mc.CALENDAR < to_date('&2'||'01','yyyymmdd') union all select mc.CALENDAR CALENDAR ,0 WEIGHT_WP_A ,0 MONEY_WP_A ,0 sumWEIGHT_WP_A ,0 sumMONEY_WP_A ,0 WEIGHT_WP_B ,0 MONEY_WP_B ,0 sumWEIGHT_WP_B ,0 sumMONEY_WP_B ,tw.WEIGHT_WP WEIGHT_WP_C ,(tw.MONEY_WP - tw.MONEY_WP_NO_FREIGHT) MONEY_WP_C ,(select sum(tw2.WEIGHT_WP) from T_RECEIVE_WP tw2 where tw2.DT_RECEIVESLIP >= to_date('&1' || '01', 'yyyymmdd') and tw2.DT_RECEIVESLIP <= mc.CALENDAR and tw2.CD_GRADE = 3 and tw2.CD_WP <> '999' and tw2.CD_WP <> '998' and tw2.FLG_DELETE = 0 ) as sumWEIGHT_WP_C ,(select sum(tw2.MONEY_WP - tw2.MONEY_WP_NO_FREIGHT) from T_RECEIVE_WP tw2 where tw2.DT_RECEIVESLIP >= to_date('&1' || '01', 'yyyymmdd') and tw2.DT_RECEIVESLIP <= mc.CALENDAR and tw2.CD_GRADE = 3 and tw2.CD_WP <> '999' and tw2.CD_WP <> '998' and tw2.FLG_DELETE = 0 ) as sumMONEY_WP_C from M_CALENDAR mc left join T_RECEIVE_WP tw on tw.DT_RECEIVESLIP = mc.CALENDAR and tw.CD_GRADE = 3 and tw.FLG_DELETE = 0 and tw.CD_WP <> '999' and tw.CD_WP <> '998' where mc.CALENDAR >= to_date('&1'||'01','yyyymmdd') and mc.CALENDAR < to_date('&2'||'01','yyyymmdd') ) t1 group by t1.CALENDAR ,t1.SUMWEIGHT_WP_A ,t1.SUMMONEY_WP_A ,t1.SUMWEIGHT_WP_B ,t1.SUMMONEY_WP_B ,t1.SUMWEIGHT_WP_C ,t1.SUMMONEY_WP_C ) t2 left join( select dtym ,sum(FREIGHT_A) as FREIGHT_A ,sum(FREIGHT_B) as FREIGHT_B ,sum(FREIGHT_C) as FREIGHT_C ,sum(FREIGHT_A_weigth) as FREIGHT_A_weigth ,sum(FREIGHT_B_weigth) as FREIGHT_B_weigth ,sum(FREIGHT_C_weigth) as FREIGHT_C_weigth from ( select to_char(tw.DT_RECEIVESLIP,'yyyymm') as dtym ,CASE WHEN tw.CD_GRADE ='1' THEN sum(tw.MONEY_WP_NO_FREIGHT) ELSE 0 END as FREIGHT_A ,CASE WHEN tw.CD_GRADE ='2' THEN sum(tw.MONEY_WP_NO_FREIGHT) ELSE 0 END as FREIGHT_B ,CASE WHEN tw.CD_GRADE ='3' THEN sum(tw.MONEY_WP_NO_FREIGHT) ELSE 0 END as FREIGHT_C ,0 as FREIGHT_A_weigth ,0 as FREIGHT_B_weigth ,0 as FREIGHT_C_weigth from T_RECEIVE_WP tw where tw.DT_RECEIVESLIP >= to_date('&1'||'01','yyyymmdd') and tw.DT_RECEIVESLIP < to_date('&2'||'01','yyyymmdd') and tw.FLG_DELETE = 0 group by tw.DT_RECEIVESLIP,tw.CD_GRADE union all select to_char(tw.DT_RECEIVESLIP,'yyyymm') as dtym ,CASE WHEN tw.CD_GRADE ='1' THEN sum(tw.MONEY_WP) ELSE 0 END as FREIGHT_A ,CASE WHEN tw.CD_GRADE ='2' THEN sum(tw.MONEY_WP) ELSE 0 END as FREIGHT_B ,CASE WHEN tw.CD_GRADE ='3' THEN sum(tw.MONEY_WP) ELSE 0 END as FREIGHT_C ,CASE WHEN tw.CD_GRADE ='1' THEN sum(tw.WEIGHT_WP) ELSE 0 END as FREIGHT_A_weigth ,CASE WHEN tw.CD_GRADE ='2' THEN sum(tw.WEIGHT_WP) ELSE 0 END as FREIGHT_B_weigth ,CASE WHEN tw.CD_GRADE ='3' THEN sum(tw.WEIGHT_WP) ELSE 0 END as FREIGHT_C_weigth from T_RECEIVE_WP tw where tw.CD_WP in ('999') and tw.DT_RECEIVESLIP >= to_date('&1'||'01','yyyymmdd') and tw.DT_RECEIVESLIP < to_date('&2'||'01','yyyymmdd') and tw.FLG_DELETE = 0 group by tw.DT_RECEIVESLIP,tw.CD_GRADE ) t3 group by t3.DTYM ) t4 on t4.dtym = '&1' left join( select dtym ,sum(ADJUST_A) as ADJUST_A ,sum(ADJUST_B) as ADJUST_B ,sum(ADJUST_C) as ADJUST_C ,sum(ADJUST_A_weigth) as ADJUST_A_weigth ,sum(ADJUST_B_weigth) as ADJUST_B_weigth ,sum(ADJUST_C_weigth) as ADJUST_C_weigth from ( select to_char(tw.DT_RECEIVESLIP,'yyyymm') as dtym ,CASE WHEN tw.CD_GRADE ='1' THEN sum(tw.MONEY_WP) ELSE 0 END as ADJUST_A ,CASE WHEN tw.CD_GRADE ='2' THEN sum(tw.MONEY_WP) ELSE 0 END as ADJUST_B ,CASE WHEN tw.CD_GRADE ='3' THEN sum(tw.MONEY_WP) ELSE 0 END as ADJUST_C ,CASE WHEN tw.CD_GRADE ='1' THEN sum(tw.WEIGHT_WP) ELSE 0 END as ADJUST_A_weigth ,CASE WHEN tw.CD_GRADE ='2' THEN sum(tw.WEIGHT_WP) ELSE 0 END as ADJUST_B_weigth ,CASE WHEN tw.CD_GRADE ='3' THEN sum(tw.WEIGHT_WP) ELSE 0 END as ADJUST_C_weigth from T_RECEIVE_WP tw where tw.CD_WP = '998' and tw.DT_RECEIVESLIP >= to_date('&1'||'01','yyyymmdd') and tw.DT_RECEIVESLIP < to_date('&2'||'01','yyyymmdd') and tw.FLG_DELETE = 0 group by tw.DT_RECEIVESLIP,tw.CD_GRADE ) t5 group by t5.DTYM ) t6 on t6.dtym = '&1' group by t2.CALENDAR ,t4.FREIGHT_A ,t4.FREIGHT_B ,t4.FREIGHT_C ,t4.FREIGHT_A_weigth ,t4.FREIGHT_B_weigth ,t4.FREIGHT_C_weigth ,t6.ADJUST_A ,t6.ADJUST_B ,t6.ADJUST_C ,t6.ADJUST_A_weigth ,t6.ADJUST_B_weigth ,t6.ADJUST_C_weigth order by calendar