SELECT
PB_BANK_CODE, ---- DB ITEM
PB_BANK_NAME, ---- DB ITEM
TOTAL_AMOUNT --- NON DB ITEM
FROM GLAS_PDC_BANKS 开发者_运维问答
where PB_COMP_CODE=:parameter.COMP_CODE AND pb_bank_code in(select distinct pc_bank_from from glas_pdc_cheques where PC_COMP_CODE=:parameter.COMP_CODE AND pc_due_dateTIME between :block01.date_from and :block01.date_to AND ISNULL(pc_discd,'X') = 'R')
order by pb_bank_code
TOTAL AMOUNT:
BEGIN
SELECT SUM(PC_AMOUNT) INTO :BLOCK02.TOTAL_AMOUNT
FROM GLAS_PDC_CHEQUES
WHERE PC_DUE_DATE BETWEEN :BLOCK01.DATE_FROM AND :BLOCK01.DATE_TO
AND PC_BANK_FROM = :BLOCK02.PB_BANK_CODE
AND NVL(PC_DISCD, 'X') = 'R';
EXCEPTION WHEN OTHERS THEN :BLOCK02.TOTAL_AMOUNT := 0;
END;
GRANT TOTAL SHOULD ALSO BE DISPLAYED.
How can i join the above two select statements
Use:
SELECT b.pb_bank_code,
b.pb.bank_name,
b.total_amount,
COALESCE(x.sum_amount, 0)
FROM GLAS_PDC_BANKS b
LEFT JOIN (SELECT c.pc_bank_from,
SUM(c.pc_amount) 'sum_amount'
FROM GLAS_PDC_CHEQUES c
WHERE c.pb_comp_code = :parameter.COMP_CODE
AND c.pc_due_date BETWEEN :block01.date_from AND :block01.date_to
AND c.pc_discd = 'R'
GROUP BY c.pc_bank_from) x ON x.pc_bank_from = b.pb_bank_code
I omitted:
NVL(PC_DISCD, 'X') = 'R'; --Oracle syntax btw
ISNULL(pc_discd,'X') = 'R'
There's no point in converting a null value to x if it isn't the one you are looking for.
精彩评论