汇总  code  和  currency 相同的列

解决方案 »

  1.   

    一个group by 不就好了??select code, names, currency, sum(amount) amount
      from (SELECT b.segment1 AS code,
                   b.vendor_name AS names,
                   a.currency_code AS currency,
                   (c.unit_price * c.quantity) AS amount
              FROM po_headers_all a, po_vendors b, po_lines_all c
             WHERE a.authorization_status <> 'CANCELIED'
               AND a.vendor_id = b.vendor_id
               AND a.po_header_id = c.po_header_id
               AND a.creation_date BETWEEN to_date('2013/01/01', 'yyyy/mm/dd') AND
                   to_date('2013/12/31', 'yyyy/mm/dd'))
     group by code, names, currency
      

  2.   

    SELECT b.segment1 AS code,
                    b.vendor_name AS names,
                    a.currency_code AS currency,
                    sum((c.unit_price * c.quantity)) AS amount
               FROM po_headers_all a, po_vendors b, po_lines_all c
              WHERE a.authorization_status <> 'CANCELIED'
                AND a.vendor_id = b.vendor_id
                AND a.po_header_id = c.po_header_id
                AND to_char(a.creation_date, 'yyyy/mm/dd') BETWEEN '2013/01/01' AND
                    '2013/12/31'
                group by b.segment1,b.vendor_name,a.currency_code