【发布时间】:2020-12-14 07:02:03
【问题描述】:
希望合并两个表,将表 2 中的数据作为行添加到表 1 中的数据。 有点困惑。刚接触 sql,所以在这里寻找一些建议。
表1
campID adID decID
camp1 ad1 dec1
camp1 ad1 dec2
camp1 ad1 dec3
表2
decID decType
dec1 1
dec2 2
dec3 3
我期待的输出
campID adID decIDTypeA decIDTypeB decIDTypeC
camp1 ad1 dec1 dec2 dec3
有人可以帮我写查询吗? 我试过了
select
t1.campID,
t1.adID,
case(
when t1.decID = t2.decID and t2.decType = 7 then t2.decID
END as decIDTypeA
when t1.decID = t2.decID and t2.decType = 7 then t2.decID
END as decIDTypeB
when t1.decID = t2.decID and t2.decType = 7 then t2.decID
END as decIDTypeC
from table1 as t1
JOIN
on table2 as t2
但它错了。
【问题讨论】: