1

下午好,我正在尝试在编写错误时满足请求。错误 # 1066 不太了解如何在我的特定情况下修复它。也许问题是我多次连接到表并且需要一个别名。

SELECT `employees`.`name`, `employees`.`surname`, `employees`.`patronymic`,
       `doc`.`name`, `doc`.`agreement`, `tank`.`name`, 
       `liquid`.`name`, `WorkPlan`.`description`
FROM `WorkPlan` , `employees` , `doc` , `tank` , `liquid`
LEFT JOIN `WorkPlan` ON `tank`.`id` = `WorkPlan`.`id_tank` 
LEFT JOIN `WorkPlan` ON `liquid`.`id` = `WorkPlan`.`id_liquid` 
LEFT JOIN `WorkPlan` ON `doc`.`id` = `WorkPlan`.`id_doc` 
AND `WorkPlan`.`id_tank` = `tank`.`id`  
AND `WorkPlan`.`id_liquid` = `liquid`.`id`  
AND `WorkPlan`.`id_doc` = `doc`.`id` 
4

1 回答 1

0

我怀疑(根据您SELECT的列列表)您想加入employees其他表。
对于每个连接,您必须在ON子句中指定与 2 个表相关的列,最好为表使用别名,这样可以缩短代码并使其更具可读性:

SELECT e.name, e.surname, e.patronymic,
       d.name, d.agreement, 
       t.name, 
       l.name, 
       w.description
FROM employees e
LEFT JOIN WorkPlan w ON e.? = w.? 
LEFT JOIN tank t ON t.id = w.id_tank 
LEFT JOIN liquid l ON l.id = w.id_liquid 
LEFT JOIN doc d ON d.id = w.id_doc 

将 替换为?与 相关的列的employees名称WorkPlan

于 2020-06-20T10:30:22.303 回答