gpt4 book ai didi

mysql - 多个 JOIN 语句

转载 作者:行者123 更新时间:2023-11-29 20:20:29 24 4
gpt4 key购买 nike

我正在尝试检索分配给项目任务的阶段、批处理、任务和员工,我几乎完成了,但我不太明白为什么每当我尝试包含 employee 时结果会变成空。表。

这是我的原话:

SELECT project.JONumber, stage.StageName, batch.BatchName, tasks.task_name, tasks_assignment.employee_number
FROM project
JOIN stage ON project.id = stage.project_id
JOIN batch ON stage.ID = batch.stage_id
JOIN tasks ON batch.id = tasks.batch_id
JOIN tasks_assignment ON tasks.id = tasks_assignment.task_id
WHERE project.id = 23441;

但是当我尝试添加另一个 JOIN 时语句,结果返回空,
以下是更新后的声明:

SELECT project.JONumber, stage.StageName, batch.BatchName, tasks.task_name, tasks_assignment.employee_number, employee.FirstName
FROM project
JOIN stage ON project.id = stage.project_id
JOIN batch ON stage.ID = batch.stage_id
JOIN tasks ON batch.id = tasks.batch_id
JOIN tasks_assignment ON tasks.id = tasks_assignment.task_id
JOIN employee ON employee.ID=tasks_assignment.employee_number
WHERE project.id = 23441;


我想也许我弄乱了最后一个 JOIN 语句,但 JOIN 不应该像 JOIN table2 ON table1.Primarykey=table2.foreignkey 一样吗? 。但也许我错了,有人可以指出我的错误吗?我真的很困惑

最佳答案

像这样尝试一次

SELECT project.JONumber, stage.StageName, batch.BatchName, tasks.task_name, tasks_assignment.employee_number, employee.FirstName
FROM project
JOIN stage ON project.id = stage.project_id
JOIN batch ON stage.ID = batch.stage_id
JOIN tasks ON batch.id = tasks.batch_id
JOIN tasks_assignment ON tasks.id = tasks_assignment.task_id
RIGHT OUTER JOIN employee ON employee.ID=tasks_assignment.employee_number
WHERE project.id = 23441;

关于mysql - 多个 JOIN 语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39528324/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com