我希望能够根据我选择的列的值内部连接两个表。
我的查询:
SELECT varA, varB, MAX(varC) varC
FROM table1
INNER JOIN table2 ON varB = table2.varB
INNER JOIN @tempTable ON varA = table1.column
INNER JOIN table3 ON varC = table3.column AND table3.column2 = 1 -- **IF NOT varA = 100**
INNER JOIN table4 ON varC = table4.column **-- IF varA = 100**
LEFT OUTER JOIN table5 ON table2.column = table5.column AND table5.column2 = 1 AND table5.column3 = 4
GROUP BY varB, varA
因此,简而言之,如果列(varA)的值不是 100,则在 table4 上进行 INNER JOIN,否则在 table3 上进行 INNER JOIN