我有3个表“Employees”,“EmployeeLeaveDays”和“EmployeeLeaves”。
我正在寻找创建一个显示休假日期和员工姓名的视图。因此,为了让我的日历工作,我将每个人分成单独的日子(EmployeeLeaveDays),其中每天都有一个FK链接到(EmployeeLeaves),其中有关于休假的其他详细信息,在EmployeeLeaves中我有一个列“employee”是一个FK回到员工,其中包含名称。
所以在我的视图中我想要返回名称,因为你可以看到是2个表,我写了这个MySQL查询但它不起作用(没有返回数据),我想知道是否还有做我需要做的事情?
SELECT
EmployeeLeaveDays.id,
EmployeeLeaveDays.employee_leave,
EmployeeLeaveDays.leave_date,
EmployeeLeaveDays.leave_type
FROM EmployeeLeaveDays
INNER JOIN EmployeeLeaves
ON EmployeeLeaveDays.employee_leave=EmployeeLeaves.employee
INNER JOIN Employees
ON EmployeeLeaves.employee=Employees.employee_id;
希望你能够看到我想要实现的目标,我怎么附上一些表结构的截图。
谢谢
答案 0 :(得分:0)
SELECT
EmployeeLeaveDays.id,
EmployeeLeaveDays.employee_leave,
EmployeeLeaveDays.leave_date,
EmployeeLeaveDays.leave_type,
EmployeeLeaves.employee,
Employees.employee_id,
Employees.first_name,
Employees.last_name
FROM EmployeeLeaveDays
LEFT JOIN EmployeeLeaves ON EmployeeLeaveDays.employee_leave = EmployeeLeaves.id
LEFT JOIN Employees ON EmployeeLeaves.employee = Employees.id;