当前位置:   article > 正文

sql列转行_sql 列转行

sql 列转行

表中数据列转行
在这里插入图片描述
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

在这里插入图片描述

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/羊村懒王/article/detail/654009
推荐阅读
相关标签
  

闽ICP备14008679号