SQL Code部分不起作用

时间:2018-06-14 16:02:54

标签: sql

我已将参考编号分为两部分' A'和' B'。现在我必须添加列并为A'添加条件。线和' B'单独划线。

    WIth tab1 AS (
     Select CONCAT(ment.ref_id,'A')  AS ronum,ment.ref_id BillOf from ment 
     where(ment.ata BETWEEN to_date('&1','DD-MON-YYYY:HH24:MI:SS')

                                    AND to_date('&2','DD-MON-YYYY:HH24:MI:SS'))
     UNION 
 Select CONCAT(ment.ref_id,'B')  AS ronum,ment.ref_id BillOf from ment 
     where(ment.ata BETWEEN to_date('&1','DD-MON-YYYY:HH24:MI:SS')

                                    AND to_date('&2','DD-MON-YYYY:HH24:MI:SS'))

    select distinct ronum,BillOf from tab1;

现在我必须划分以下代码

A行AS Amount1列:

    select sum(charge_amt) 
    from line_charges 
    where ppc_ind='C' 
    and import_export_ind='E' 
    and charge_code='FRTRV' 
    and line_tx_id=ment.line_tx_id

第A行AS Amount2列:

  select sum(charge_amt) 
    from line_charges 
    where ppc_ind='C' 
    and import_export_ind='E' 
    and charge_code='FSCRV' 
    and line_tx_id=ment.line_tx_id

B行AS Amount1列:

   select sum(charge_amt) 
    from line_charges 
    where ppc_ind='C' 
    and import_export_ind='I' 
    and charge_code='HANRV' 
    and line_tx_id=ment.line_tx_id

B行AS Amount2列:

     select sum(charge_amt)*0.1
    from line_charges 
    where ppc_ind='C' 
    and import_export_ind='I' 
    and charge_code='HANRV' 
    and line_tx_id=ment.line_tx_id

0 个答案:

没有答案