我有四张桌子A,B,C和D.
Table A: value1, city
Table B: value2, city
Table C: value3, city
Table D: value1, value2, value3
我需要选择value2(我从表D中猜测),其中value1和value3在表D中的同一行,并且两者都具有相同的" city"在表A和C的行中。
因此,如果表A有行
13, Chicago
14, Milwaukee
15, St. Louis
和表C有行
78, Chicago
89, St. Paul
94, St. Louis
和表D有行
13, One, 89
13, Two, 78
14, Three, 78
15, Four, 94
然后我需要打印出来:
Two
Four
答案 0 :(得分:3)
select
value2
from
tablea a
inner join tablec c on a.value1= c.value1
inner join tableb b on c.value3= b.value3
where
b.city = a.city
答案 1 :(得分:1)
SELECT TableD.value2
FROM TableD
JOIN TableC ON TableC.value3=TableD.value3
JOIN TableA ON TableA.value1=TableD.value1 AND TableA.city = TableC.city