一、pivot 行转列

使用表dm_custbd_lab_c_month

表结构如下:

oracle中pivot和unpivot函数用法举例


行转列语句:

select *
  from (select t.c_month, t.c_channel, t.c_soto, t.label_code, t.label_value
          from dm_custbd_lab_c_month t
         where t.c_month = '201706'
           and t.label_code in ('LAB_004', 'LAB_001', 'LAB_002')) pivot(max(label_value) for label_code in('LAB_004' as
                                                                                                           LAB_004,
                                                                                                           'LAB_001' as
                                                                                                           LAB_001,
                                                                                                           'LAB_002' as
                                                                                                           LAB_002));

结果展示:oracle中pivot和unpivot函数用法举例


二、列转行 UNPIVOT

表结构展示:

oracle中pivot和unpivot函数用法举例

列转行脚本:

select *
  from (select t.c_month, t.c_channel, t.c_soto, t.symb00034, t.symb00015
          from dm_custbd_k_c_month_hor t
         where t.c_month = '201706') unpivot((kpi_value) for index_id in(SYMB00034,
                                                                         SYMB00015))

oracle中pivot和unpivot函数用法举例

相关文章:

  • 2021-08-01
  • 2021-07-05
  • 2022-12-23
  • 2022-12-23
  • 2021-10-21
  • 2021-05-21
  • 2022-02-03
猜你喜欢
  • 2021-10-19
  • 2021-09-20
  • 2022-12-23
  • 2021-08-20
  • 2021-06-27
  • 2021-11-12
  • 2021-08-28
相关资源
相似解决方案