很多业务需求存储数据的时候都采取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相关知识