• 【Oracle】Oracle中多列转成多行


      今天做BI的时候遇到这样一个问题,要将多列转化成多行,简单记录下是如何操作的。

    1、问题:要将第一个图的两条数据转化成第二个图显示的结果

                                                                   

    2、实现:具体实现要使用到Oracle的 unpivot 函数

     1 select in_hos_num,patient_name,out_hos_date,l_hos_type,
     2     icd_9_code, icd_9_name,in_hos --取得是别名
     3 from dim_diagnosis   
     4     unpivot((icd_9_code,icd_9_name,in_hos)--设置多列合并成一列的别名
     5     for qc in ((icd_9_main,icd_9_main_name,in_hos_main) ,--实际的字段和别名对应
     6         (icd_9_other1,icd_9_other1_name, in_hos_other1),
     7         (icd_9_other2,icd_9_other2_name, in_hos_other2),
     8         (icd_9_other3,icd_9_other3_name, in_hos_other3),
     9         (icd_9_other4,icd_9_other4_name, in_hos_other4),
    10         (icd_9_other5,icd_9_other5_name, in_hos_other5),
    11         (icd_9_other6,icd_9_other6_name, in_hos_other6),
    12         (icd_9_other7,icd_9_other7_name, in_hos_other7),
    13         (icd_9_other8,icd_9_other8_name, in_hos_other8),
    14         (icd_9_other9,icd_9_other9_name, in_hos_other9),
    15         (icd_9_other10,icd_9_other10_name, in_hos_other10),
    16         (icd_9_other11,icd_9_other11_name, in_hos_other11),
    17         (icd_9_other12,icd_9_other12_name, in_hos_other12),
    18         (icd_9_other13,icd_9_other13_name, in_hos_other13))  
    19 );
  • 相关阅读:
    2019年11月4日随堂测试 最多输入字母统计
    写增删改查中间遇到的问题
    2019年12月9日下午自习成果
    2019年12月16日 分级考试
    2019年11月18日 JAVA期中考试 增删改查
    sql语言积累
    【转载】Java项目中常用的异常处理情况总结
    泛型
    C#数字格式化输出
    委托,Lambda的几种用法
  • 原文地址:https://www.cnblogs.com/handongxue/p/10677569.html
Copyright © 2020-2023  润新知