zoukankan      html  css  js  c++  java
  • oracle 横向列变为纵向列

    很多业务需求存储数据的时候都采取key/value的形式,展示时则需要key1,key2,key3....展示

    效果如下:

    图片说明

    sql语句如下

    SELECT 
    
    ROUND(SUM(CASE WHEN DATA_ITEM_CODE='BACKN52'  THEN DATA_ITEM_VALUE ELSE '0' END),2) AS 磨煤机入口压力,ROUND(SUM(CASE WHEN DATA_ITEM_CODE='BACKN53'  THEN DATA_ITEM_VALUE ELSE '0' END),2)  AS 磨煤机加载压力,
    
    ROUND(SUM(CASE WHEN DATA_ITEM_CODE = 'BACKN54'  THEN DATA_ITEM_VALUE ELSE '0' END), 2) AS 收粉器入口压力, ROUND(SUM(CASE WHEN DATA_ITEM_CODE = 'BACKN55'  THEN DATA_ITEM_VALUE ELSE '0' END), 2)  AS 收粉器出口压力,
    
    ROUND(SUM(CASE WHEN DATA_ITEM_CODE = 'BACKN56'  THEN DATA_ITEM_VALUE ELSE '0' END), 2) AS 煤粉仓重, ROUND(SUM(CASE WHEN DATA_ITEM_CODE = 'BACKN57'  THEN DATA_ITEM_VALUE ELSE '0' END), 2)  AS 废气温度
    
     from(SELECT * FROM TABLE_NAME WHERE WORK_TIME >= TO_CHAR('20200921' - 1) || '200000' AND WORK_TIME <'20200921'|| '200000' ) group by WORK_TIME ORDER BY WORK_TIME;

    关键字 CASE WHEN...THEN..ELSE..END
    分组汇总后进行纵列变横列(上边的数据、图片仅供展示)


    后期会更新sql相关知识

  • 相关阅读:
    Perl 简介
    一定时间后延时变长问题
    CPAN常见问题集
    J2SE简介
    brian的Perl问题之万能指南
    清洁工 VS 亿万富翁
    关于VC中的"stdafx.h"
    Perl模式匹配
    wiki介绍
    生活中10大省钱小秘诀 白领一族"必备诀窍"
  • 原文地址:https://www.cnblogs.com/shenbing/p/13776338.html
Copyright © 2011-2022 走看看