列转行

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

技术分享图片

 










以上是关于列转行的主要内容,如果未能解决你的问题,请参考以下文章

MySQL行转列与列转行

关于ORACLE列转行的问题

SAS行转列&&列转行

Hive 行转列 & 列转行

Oracle列转行,行转列

oracle列转行函数