= to_date(?, 'yyyymmdd') and trunc(k.INSTOCK_TIME) <= to_date(?, 'yyyymmdd') then nvl(k.inListCount, 0) end), 0) MONTH_1COUNT, nvl(sum(case when trunc(k.INSTOCK_TIME) >= to_date(?, 'yyyymmdd') and trunc(k.INSTOCK_TIME) <= to_date(?, 'yyyymmdd') then nvl(k.inListWgt, 0) end), 0) MONTH_1, nvl(sum(case when trunc(k.OUTSTOCK_TIME) = to_date(?, 'yyyymmdd') then nvl(k.outListCount, 0) end), 0) DAY_2COUNT, nvl(sum(case when trunc(k.OUTSTOCK_TIME) = to_date(?, 'yyyymmdd') then nvl(k.outListWgt, 0) end), 0) DAY_2, nvl(sum(case when trunc(k.OUTSTOCK_TIME) >= to_date(?, 'yyyymmdd') and trunc(k.OUTSTOCK_TIME) <= to_date(?, 'yyyymmdd') then nvl(k.outListCount, 0) end), 0) MONTH_2COUNT, nvl(sum(case when trunc(k.OUTSTOCK_TIME) >= to_date(?, 'yyyymmdd') and trunc(k.OUTSTOCK_TIME) <= to_date(?, 'yyyymmdd') then nvl(k.outListWgt, 0) end), 0) MONTH_2, sum(k.AWEIGHT) as AWEIGHT, sum(k.MATCOUNT) as MATCOUNT, sum(k.MATWGT) as MATWGT from (select JUDGE_STOVE_NO, BATCH_NO, --BATCH_GROUD_NO, BELONG_CODE, sum(ACT_COUNT) ORIGINAL_COUNT, sum(ACT_WEIGHT) ORIGINAL_AMOUNT, 0 inListCount, 0 inListWgt, 0 outListCount, 0 outListWgt, 0 AWEIGHT, 0 MATCOUNT, 0 MATWGT, null OUTSTOCK_TIME, null INSTOCK_TIME from ydm_zc_initial t where t.bal_year_month = ? and t.handle_log = '1' and t.belong_code = '#condtions#' group by t.judge_stove_no, t.batch_no, --t.batch_groud_no, BELONG_CODE union all SELECT JUDGE_STOVE_NO, BATCH_NO, --BATCH_GROUD_NO, BELONG_CODE, 0 ORIGINAL_COUNT, 0 ORIGINAL_AMOUNT, ACT_COUNT inListCount, ACT_WEIGHT inListWgt, 0 outListCount, 0 outListWgt, 0 AWEIGHT, 0 MATCOUNT, 0 MATWGT, null OUTSTOCK_TIME, INSTOCK_TIME INSTOCK_TIME FROM YDM_BC_INLIST WHERE INSTOCK_TYPE_CODE IN ('800701', '800702', '800704', '800706', '800707') AND TRUNC(INSTOCK_TIME) >= TO_DATE(?, 'YYYYMMDD') AND TRUNC(INSTOCK_TIME) <= TO_DATE(?, 'YYYYMMDD') and belong_code = '#condtions#' union all select JUDGE_STOVE_NO, BATCH_NO, --BATCH_GROUD_NO, BELONG_CODE, 0 ORIGINAL_COUNT, 0 ORIGINAL_AMOUNT, 0 inListCount, 0 inListWgt, ACT_COUNT outListCount, (case when PONDER_NO is null then nvl(ACT_WEIGHT, 0) else nvl(PONDER_GROSS_WT, 0) end) outListWgt, 0 AWEIGHT, 0 MATCOUNT, 0 MATWGT, OUTSTOCK_TIME OUTSTOCK_TIME, null INSTOCK_TIME from YDM_BC_OUTLIST where OUTSTOCK_TYPE_CODE = '800809' and TRUNC(OUTSTOCK_TIME) >= TO_DATE(?, 'YYYYMMDD') AND TRUNC(OUTSTOCK_TIME) <= TO_DATE(?, 'YYYYMMDD') and belong_code = '#condtions#' union all select JUDGE_STOVE_NO, BATCH_NO, --BATCH_GROUD_NO, BELONG_CODE, 0 ORIGINAL_COUNT, 0 ORIGINAL_AMOUNT, 0 inListCount, 0 inListWgt, 0 outListCount, 0 outListWgt, sum(ACT_WEIGHT) AWEIGHT, 0 MATCOUNT, 0 MATWGT, null OUTSTOCK_TIME, null INSTOCK_TIME from YDM_BC_STOCKTAKINGLIST e where TRUNC(e.stocktaking_time) >= to_date(?, 'YYYYMMDD') and TRUNC(e.stocktaking_time) <= to_date(?, 'YYYYMMDD') and e.belong_code = '#condtions#' group by JUDGE_STOVE_NO, BATCH_NO, --BATCH_GROUD_NO, BELONG_CODE union all ( SELECT F.JUDGE_STOVE_NO, F.BATCH_NO, --F.BATCH_GROUD_NO, BELONG_CODE, 0 ORIGINAL_COUNT, 0 ORIGINAL_AMOUNT, 0 inListCount, 0 inListWgt, 0 outListCount, 0 outListWgt, 0 AWEIGHT, sum(F.Act_Count) MATCOUNT, sum(F.Act_Weight) MATWGT, null OUTSTOCK_TIME, null INSTOCK_TIME FROM MAT_BC_M F, YDM_BC_BUTTRESS G WHERE F.MAT_NO = G.MAT_NO AND F.PRODUCT_FLAG = '801401' AND F.belong_code = '#condtions#' group by F.Judge_Stove_No, F.Batch_No, -- F.Batch_Groud_No, F.BELONG_CODE)) k group by k.Judge_Stove_No, k.Batch_No, --k.Batch_Groud_No, BELONG_CODE) h group by JUDGE_STOVE_NO, BATCH_NO --BATCH_GROUD_NO ]]>