[英]oracle database merge results from multiple tables
I want to merge data coming from two tables :- 我想合并来自两个表的数据:
T1 ----- id c1 c2 switch 1 joe darling Y 1 maria kk N T2 -------------- id d1 d2 1 sydney austraila
now if the switch in T1 is 'Y' 现在,如果T1中的开关为“ Y”
i want the output as 我希望输出为
joe darling sydney australia // which is fine..
and if switch is 'N' 如果开关为“ N”
i still want the first and last name based on switch which is 'Y' and rest of the values from T2 table. 我仍然希望基于开关的名字和姓氏为“ Y”,以及T2表中其余的值。
joe darling sydney australia //how to achieve this.
Suppose you've got only one Y
switch per ID then try this: 假设每个ID只有一个Y
开关,然后尝试以下操作:
SELECT
T12.C1, T12.C2, T2.d1, T2.D2
FROM T1
JOIN T1 as T12 ON (T1.ID=T12.ID) AND (T12.switch='Y')
LEFT JOIN T2 on (T1.ID=T2.ID)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.