在第二个左连接的MYSQL中使用一个左连接表中的列

时间:2017-12-03 14:50:21

标签: mysql

让我们说我们需要类似这样的查询:

SELECT table1.c1, table1.c2, c3, c4 FROM table1
LEFT JOIN (
    SELECT c1II, c3II as c3 FROM table2) joined1 ON table1.c1 = joined1.c1II

LEFT JOIN (
    SELECT c1III, c4II as c4 FROM table3 WHERE c4 > joined1.c3) joined2 ON table1.c1 = joined2.c1II

我尝试运行此查询并收到以下错误:

  

查询错误(1054):where子句

中的未知列join1.c3

我该怎么做才能让它有效?

1 个答案:

答案 0 :(得分:1)

希望这有帮助

SELECT table1.c1, table1.c2, c3, c4 
FROM table1
LEFT JOIN  table2 ON table1.c1 = table2.c1II
LEFT JOIN  table3 ON c4 > table2.c3 AND table1.c1 = table3.c1II