列转行
Posted zyzx
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了列转行相关的知识,希望对你有一定的参考价值。
表中数据列转行
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
以上是关于列转行的主要内容,如果未能解决你的问题,请参考以下文章