老衲在此谢过了~ ------最佳解决方案-------------------- WITH TEST AS (
SELECT '1' AS Wafer_id ,20 AS Bin_Id,1 as Bin_QTY FROM DUAL
UNION ALL
SELECT '1' AS Wafer_id ,15 AS Bin_Id,1 as Bin_QTY FROM DUAL
UNION ALL
SELECT '1' AS Wafer_id ,14 AS Bin_Id,1 as Bin_QTY FROM DUAL
UNION ALL
SELECT '1' AS Wafer_id ,13 AS Bin_Id,14 as Bin_QTY FROM DUAL
UNION ALL
SELECT '1' AS Wafer_id ,5 AS Bin_Id,2 as Bin_QTY FROM DUAL
UNION ALL
SELECT '1' AS Wafer_id ,10 AS Bin_Id,37 as Bin_QTY FROM DUAL
UNION ALL
SELECT '1' AS Wafer_id ,6 AS Bin_Id,13 as Bin_QTY FROM DUAL
UNION ALL
SELECT '1' AS Wafer_id ,0 AS Bin_Id,1067 as Bin_QTY FROM DUAL
UNION ALL
SELECT '1' AS Wafer_id ,12 AS Bin_Id,7 as Bin_QTY FROM DUAL
UNION ALL
SELECT '2' AS Wafer_id ,12 AS Bin_Id,4 as Bin_QTY FROM DUAL
)
select max(decode(rn,1,Bin_Id,'')) as ONE,
max(decode(rn,1,Bin_QTY,'')) as ONE_num,
max(decode(rn,2,Bin_Id,'')) as TWO,
max(decode(rn,2,Bin_QTY,'')) as TWO_num,
max(decode(rn,3,Bin_Id,'')) as THREE,
max(decode(rn,3,Bin_QTY,'')) as THREE_num,
max(decode(rn,4,Bin_Id,'')) as FOUR,
max(decode(rn,4,Bin_QTY,'')) as FOUR_num,
max(decode(rn,5,Bin_Id,'')) as FIVE,
max(decode(rn,5,Bin_QTY,'')) as FIVE_num
from (
select row_number()over(partition by Wafer_id order by Bin_QTY desc) as rn,Wafer_id,Bin_Id,Bin_QTY from test) where rn <6 GROUP BY Wafer_id ------其他解决方案--------------------