sql 合并满足条件的列
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 to_char(a.creation_date, 'yyyy/mm/dd') BETWEEN '2013/01/01' AND
'2013/12/31'
结果:
code names currency amount
A1 1 RMB 500
A1 1 RMB 500
A1 1 HKD 500
A2 2 HKD 500
希望结果:
code names currency amount
A1 1 RMB 1000
A1 1 HKD 500
A2 2 HKD 500
谢谢!
------解决方案--------------------一个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
------解决方案--------------------