我有两个共享同一列 ( C
) 的表,但 SQL 告诉我有一个错误
这是第一个查询的第一个表:
SELECT E.C AS C,
COUNT(C) AS CC
FROM E
GROUP BY E.C
这是第二个查询:
SELECT E.C AS C,
COUNT(C) AS Num
FROM E, G
WHERE E.G = G.L
AND G.G <
(SELECT min(G.G)
FROM G
WHERE G.L = "BLAH")
GROUP BY E.C
所以我试图简单地将这两者放在一起,放在JOIN
它们之间。但这并没有加入他们,即使他们共享同一列C
。它只是说我有语法错误。怎么了?我该如何解决?我已经确认,当单独运行时,它们会产生带有列的正确输出C
以下是总JOIN
执行情况
(SELECT E.C AS C,
COUNT(C) AS CC
FROM E
GROUP BY E.C)
JOIN
(SELECT E.C AS C,
COUNT(C) AS Num
FROM E, G
WHERE E.G = G.L
AND G.G <
(SELECT min(G.G)
FROM G
WHERE G.L = "BLAH")
GROUP BY E.C)
错误是错误代码1064,SQL状态42000:您的SQL语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以获取在 'JOIN 附近使用的正确语法
(SELECT E.C AS C,
COUNT(C) AS Num' at line 6
Line 1, column 1