仅当三个表之一引用父表时,才从三个表中选择数据

我有三个桌子的人,他的汽车,他的房子。如果孩子(汽车,房屋)表之一引用了父母(人),则我需要选择拥有他的汽车和房屋的人。

我尝试了join,但不知道在这种情况下如何使用OR。

Table person
id  name
1   Mark
2   David
3   Mike
4   Andrew

Table house
id  city        person
1   Moscow        1
2   Chicago       1
3   New York      2
4   Boston        2

Table car     
id   brand      person
1    bmw        4
2    opel       4
3    toyota     2
4    volvo      2

结果应该是

name    city              car
Mark   Moscow Chicago
David  New York Boston   toyota volvo
Andrew                   bmw opel
X00400 回答:仅当三个表之一引用父表时,才从三个表中选择数据

您可以Invoke-Sqlcmd -ServerInstance "xxxx" -Database "Vincent" -Query $SqlStatement ` -Username "rminder" -Password "xxxx" | Set-Content -Path C:\Temp\MyProject\SUP_20160401.Csv 两次,并确保其中一个连接成功。剩下的就是聚合:

left join

Demo on DB Fiddle

name   | cities          | brands      
:----- | :-------------- | :-----------
Mark   | Chicago Moscow  | null        
David  | Boston New York | toyota volvo
Andrew | null            | bmw opel    
本文链接:https://www.f2er.com/3163321.html

大家都在问