日期:2014-05-17 浏览次数:20844 次
WITH TB AS (SELECT 'a' AS 姓名, '看书' AS 兴趣 FROM DUAL UNION ALL SELECT 'b' AS 姓名, '篮球' AS 兴趣 FROM DUAL UNION ALL SELECT 'a' AS 姓名, '旅行' AS 兴趣 FROM DUAL UNION ALL SELECT 'a' AS 姓名, '足球' AS 兴趣 FROM DUAL UNION ALL SELECT 'b' AS 姓名, '看书' AS 兴趣 FROM DUAL) SELECT 姓名, NVL(MAX(DECODE(CNT, 1, 兴趣)), '无') 兴趣1, NVL(MAX(DECODE(CNT, 2, 兴趣)), '无') 兴趣2, NVL(MAX(DECODE(CNT, 3, 兴趣)), '无') 兴趣3, NVL(MAX(DECODE(CNT, 4, 兴趣)), '无') 兴趣4, NVL(MAX(DECODE(CNT, 5, 兴趣)), '无') 兴趣5 FROM (SELECT 姓名, 兴趣, ROW_NUMBER() OVER(PARTITION BY 姓名 ORDER BY 兴趣) CNT FROM TB) T GROUP BY T.姓名