У меня есть таблица (MyTable) с этими столбцами: точкой сигнализации load_id countAlarms ...Oracle SQL присоединиться к той же таблице
и я использую этот запрос:
select point, decode(alarm,0,'new','rec') NewRec, sum (countAlarms) total_alarms, load_id from MyTable
where 1=1
--and load_id = (select max(load_id) from MyTable) -0
group by point, decode(alarm,0,'new','rec'), load_id
order by 1, 2
)
к получите что-то вроде этого:
point1 new 1200 111113
point1 rec 6000 111113
point2 new 1220 111113
point2 rec 3000 111113
point3 new 3220 111113
point3 rec 1000 111113
point1 new 1300 111112
point1 rec 6300 111112
point3 new 1220 111112
point3 rec 1100 111112
point1 new 1300 111111
point1 rec 6300 111111
point2 new 1120 111111
point2 rec 3100 111111
point3 new 1220 111111
point3 rec 1100 111111
....
что мне нужно:
point newRec point point point
---------------------------------------
point1 new 1200 1300 1300
point1 rec 6000 6300 6300
point2 new 1220 1120
point2 rec 3000 3100
point3 new 3220 1220 1220
point3 rec 1000 1100 1100
Я попытался с полным внешним соединением, но он не работает :(
Использовать Self присоединяется ... –