我有一個基地臺與以下數據數據插入使用SQL/PLSQL
table1的
NUMBER TYPE DATE
1 ABC 2015-05-05 10:00:00
1 XYZ 2015-05-05 11:00:00
我所需要的輸出表 「測試」 爲具有低於細節
id T1 TYPE_1 T2 TYPE_2
1 10:00:00 ABC 11:00:00 XYZ
我有以下嘗試,但它不起作用。我是sql plsql的新手。
begin
if exists (select distinct id from test where id in (select distinct NUMBER from table1))
begin
update test set
T1 =
(
case
when TYPE='ABC' then DATE end as T1
) ,
T2 =
(
case
when TYPE='XYZ' then DATE end as T2
)
where TA = table1.NUMBER
end
else
begin
insert into test (
T1,
T2
)
select (
case when TYPE='ABC' then DATE end as T1,
case when TYPE='XYZ' then DATE end as T2
)
from table1 where NUMBER=test.id
end
end
如果每個數字每種類型有多於一行,該怎麼辦? –
每個類型每個編號不會超過1行 – tester