赞
踩
表中数据列转行
SELECT PEOPLE_NAME,
MAX(DECODE(RN, 1, ILL_NAME, NULL)) AS ILL_NAME1,
MAX(DECODE(RN, 2, ILL_NAME, NULL)) AS ILL_NAME2,
MAX(DECODE(RN, 3, ILL_NAME, NULL)) AS ILL_NAME3,
MAX(DECODE(RN, 4, ILL_NAME, NULL)) AS ILL_NAME4
FROM (SELECT A.PEOPLE_NAME,
A.ILL_NAME,
ROW_NUMBER() OVER(PARTITION BY PEOPLE_NAME ORDER BY ILL_NAME) AS RN
FROM ILL_NAME A) T
GROUP BY PEOPLE_NAME
ORDER BY 1
、
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。