oracle 随记

SELECT a.tax_num,
       a.site_code,
       a.site_name,
       unionTable.operated_by,
       unionTable.operation_date as RQ,
       count(decode(unionTable.operation_type, 'NORMAL', 1, null)) DRZCFPS,
       count(decode(unionTable.operation_type, 'REFUND', 1, null)) DRTPS,
       count(decode(unionTable.operation_type, 'INVALID', 1, null)) DRFPS,
       sum(unionTable.ZCPFLJE) ZCPFLJE,
       sum(unionTable.TPFLJE) TPFLJE,
       sum(unionTable.FPFLJE) FPFLJE,
       imd.dept_cd,
       imd.dept_name
  FROM (SELECT b.invoice_code,
               b.invoice_num,
               b.operation_type,
               max(b.order_num) as order_num,
               to_char(b.operation_date, 'yyyy-mm-dd') as operation_date,
               b.operated_by,
               b.sales_belong_comp,
               SUM(DECODE(b.operation_type,
                          'NORMAL',
                          nvl(e.final_price * e.qty, 0) +
                          nvl(e.detail_shipping_cost, 0) -
                          nvl(e.card_paid_partprice, 0) -
                          nvl(e.card_paid_shippingprice, 0),
                          0)) ZCPFLJE,
               SUM(DECODE(b.operation_type,
                          'REFUND',
                          (case
                            when e.final_price > 0 then
                             - (nvl(e.final_price * e.qty, 0) +
                                nvl(e.detail_shipping_cost, 0) -
                                nvl(e.card_paid_partprice, 0) -
                                nvl(e.card_paid_shippingprice, 0))
                            else
                             (nvl(e.final_price * e.qty, 0) +
                             nvl(e.detail_shipping_cost, 0) -
                             nvl(e.card_paid_partprice, 0) -
                             nvl(e.card_paid_shippingprice, 0))
                          end),
                          0)) TPFLJE,
               SUM(DECODE(b.operation_type,
                          'INVALID',
                          nvl(e.final_price * e.qty, 0) +
                          nvl(e.detail_shipping_cost, 0) -
                          nvl(e.card_paid_partprice, 0) -
                          nvl(e.card_paid_shippingprice, 0),
                          0)) FPFLJE
          FROM iv_order_invoice b, iv_order_detail e
         where b.order_num = e.order_num
           and b.ord_line_id = e.line_id
         group by b.operation_type,
                  b.invoice_code,
                  b.invoice_num,
                  to_char(b.operation_date, 'yyyy-mm-dd'),
                  b.operated_by,
                  b.sales_belong_comp
        ) unionTable,
       iv_mst_site a,
       iv_order_header c,
       iv_mst_department imd
 where a.site_code = unionTable.sales_belong_comp
   and imd.dept_cd = c.dept_cd
   and c.order_num = unionTable.order_num
 group by a.tax_num,
          a.site_code,
          a.site_name,
          unionTable.operated_by,
          unionTable.operation_date,
          imd.dept_cd,
          imd.dept_name;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值