我有两张桌子T1和T2。
T1:
T1CN1 T1CN2 T1CN3
------ ------ ------
T1C1R1 T1C2R1 T1C3R1
T1C1R2 T1C2R2 T1C3R2
T1C1R3 T1C2R3 T1C3R3
T1C1R4 T1C2R4 T1C3R4
T1C1R5 T1C2R5 T1C3R5
T1C1R6 T1C2R6 T1C3R6
T2:
T2CN1 T2CN2 T2CN3 T2CN4 T2CN5 T2CN6 T2CN7
------ ------ ------ ------ ------ ------ ------
T2C1R1 T2C2R1 T2C3R1 T2C4R1 T2C5R1 T2C6R1 T2C7R1
T2C1R2 T2C2R2 T2C3R2 T2C4R2 T2C5R2 T2C6R2 T2C7R2
T3:
T3CN1
------
T3C1R1
我需要一个声明来给出结果:
结果:
T1CN1 T1CN2 T1CN3
------ ------ ------
T1C1R1 T2C2R1 T1C3R1
T1C1R2 T2C3R1 T1C3R2
T1C1R3 T2C4R1 T1C3R3
T1C1R4 T2C5R1 T1C3R4
T1C1R5 T2C6R1 T1C3R5
T1C1R6 T2C7R1 T1C3R6
如果T3C1R1 = T2C1R1
否则它应该将T2的第二行复制到T1的第二列
如何使用SQL语句实现此目的?
仅供参考,
T1CN1 ----->表1 columnname1(T1的第一列名称)
...
T1C1R1 ----->表1 column1row1(T1的C1R1处的数据)
答案 0 :(得分:0)
您可以在所需列上使用join,join T1和T2。 如果需要,使用case语句检查值并更改值。
插入T1(列表) 选择T1C1, T1C1 ='值x'然后T1C1否则T2C2结束 从T1加入T2上 T1C1 = T2C2