我正在尝试在 SQLite3 中执行内部联接,但它不起作用。我不断收到错误消息,指出 table2 中的字段名称不明确。
如有任何意见,我们将不胜感激。
SELECT
table1.id, table1.cd1, table1.cd2, table1.cd3, table1.cd4, table2.ab
FROM
table1
INNER JOIN table2 ON table2.dx = table1.cd1
INNER JOIN table2 ON table2.dx = table1.cd2
INNER JOIN table2 ON table2.dx = table1.cd3
INNER JOIN table2 ON table2.dx = table1.cd4
GROUP BY 1, 2, 3, 4, 5, 6
表2中的字段“dx”对应表1中的四个不同字段:“cd1”、“cd2”、“cd3”、“cd4”。
最佳答案
您需要表别名:
SELECT t1.id, t1.cd1, t1.cd2, t1.cd3, t1.cd4, ?.ab
FROM table1 t1 JOIN
table2 t21
ON t21.dx = t1.cd1 JOIN
table2 t22
ON t22.dx = t1.cd2 JOIN
table2 t23
ON t23.dx = t1.cd3 JOIN
table2 t24
ON t24.dx = t1.cd4
GROUP BY 1, 2, 3, 4, 5, 6;
我不知道 ab
应该来自哪个表,所以你需要填写它。
关于sql - SQLite3 中的内部连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44961306/