我有两张桌子
TableA Column1, Column2,Column3, Column4
TableB Column1, Column2,Column3, Column4
查询修改:
Select Column2,Column3, Column4
From TableA
如果 TableB 中存在 TableA.Column2 的值,我将如何修改上述查询以从 TableB 中选择 Column3?它还必须是 TableB.Column1 的最大值。
TableA
Column1 Column2 Column3 Column4
1 A zebra apple
2 C lion orange
3 R giraffe banana
TableB
Column1 Column2 Column3 Column4
1 Q snail rock
2 C frog stone
3 Z giraffe tree
4 C walrus limb
Result
Column2 Column3 Column4
A zebra apple
C walrus orange
R giraffe banana
它可能是这样的:
Select TableA.Column2,Case When Exists(Select TableB.Column3 From Table3
Where Table2.Column = TableB.Column2 ) Then Select Table2.Column3 Where [Table2.Column1 is max value], Column4
From TableA