日期:2014-05-16 浏览次数:21086 次
select product_line,sum(defect_qty),sum(inspect_qty) from (select product_line,defect_qty,inspect_qty from fr_badness group by product_line,defect_qty,inspect_qty) group by product_line
------解决方案--------------------
---------------------------- -- Author :qiudf(day day up) -- Date :2011-10-12 9:10 -- Verstion: ---------------------------- --> 测试数据:[a] with a as (select 'a' as product_line , '1101' as barcode, '2' as defect_qty, '10' as inspect_qty, 't1' as position, sysdate as create_date from dual union all select 'a' as product_line , '1101' as barcode, '2' as defect_qty, '10' as inspect_qty, 't2' as position, sysdate as create_date from dual union all select 'a' as product_line , '1102' as barcode, '9' as defect_qty, '20' as inspect_qty, 't3' as position, sysdate as create_date from dual union all select 'b' as product_line , '1103' as barcode, '3' as defect_qty, '12' as inspect_qty, 't4' as position, sysdate as create_date from dual union all select 'b' as product_line , '1103' as barcode, '3' as defect_qty, '12' as inspect_qty, 't5' as position, sysdate as create_date from dual union all select 'a' as product_line , '1101' as barcode, '2' as defect_qty, '10' as inspect_qty, 't1' as position, sysdate as create_date from dual ) select product_line,sum(defect_qty),sum(inspect_qty) from ( select product_line,barcode,defect_qty,inspect_qty,row_number() over(partition by product_line,barcode,defect_qty,inspect_qty order by product_line) rn from a ) where rn=1 group by product_line --result: a 11 30 b 3 12
------解决方案--------------------
#4楼的正解
------解决方案--------------------
select product_line,sum(distinct defect_qty),sum(distinct inspect_qty)
from 你的表
------解决方案--------------------