实现思路
–查询出的数据作为数据块
WITH TIMESUM AS (
SELECT times, run, wait, STOP, other FROM AD_DEV_OEE A WHERE A.DEV_ID = ‘SMT-01’ GROUP BY DEV_ID
)
/把先把需要输出的行的信息标识出来:其中times是原有的列,month_str是用于存放(run/stop/wait/other)即原有的列通过一个新的month_str去存放,income是新增加用于存放原数据行(run/stop/wait/other)的数据/
SELECT r.times,KEY AS month_str,VALUE AS income
FROM
( SELECT dev_id, times, row_to_json ( t.* ) AS line FROM TIMESUM t ) AS r
JOIN lateral json_each_text ( r.line ) ON TRUE
WHERE KEY IN ( ‘run’, ‘stop’, ‘wait’, ‘other’ )
表述的较为简单,请见谅。