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相关知识

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值