这条sql怎么改?
SELECT NAME, (DECODE (kpi_id, '210504', kpi_value, '0')) 铁塔角度x,
(DECODE (kpi_id, '210505', kpi_value, '0')) 铁塔角度y, (DECODE (kpi_id, '210501', kpi_value, '0')) 温度
FROM (SELECT his.kpi_value,
TO_CHAR (his.cll_time, 'MM-DD HH24:MI:SS') AS NAME,
his.kpi_id
FROM table1 his where his.kpi_id IN ('210505', '210504','210501'))
这样一条sql
得出的结果是 同一时间多条记录
NAME 铁塔角度x 铁塔角度y 温度
09-01 00:01:32 1 0 0
09-01 00:01:32 0 1 0
09-01 00:01:32 0 0 1
09-01 00:02:32 2 0 0
09-01 00:02:32 0 0 2
要求是 把多条数据在同时间合并
NAME 铁塔角度x 铁塔角度y 温度
09-01 00:01:32 1 1 1
09-01 00:02:32 2 0 2
各个帮忙看看sql怎么写
------解决方案--------------------
SQL code
--这个应该可以,你整的也太麻烦了
select
TO_CHAR (his.cll_time, 'MM-DD HH24:MI:SS') AS NAME,
max(DECODE (kpi_id, '210504', kpi_value, '0')) 铁塔角度x,
max(DECODE (kpi_id, '210505', kpi_value, '0')) 铁塔角度y,
max(DECODE (kpi_id, '210501', kpi_value, '0')) 温度
from table1 his
where his.kpi_id IN ('210505', '210504','210501')
group by TO_CHAR (his.cll_time, 'MM-DD HH24:MI:SS');