简体   繁体   English

如何在 MySQL 中将日历表与另外 2 个表进行内部连接

[英]How to inner join calendar table with 2 more tables in MySQL

I have 2 tables that I have to inner join in PHP MySQL but I can't really understand the syntax on inner join SQL syntax.我有 2 个表必须在 PHP MySQL 中进行内连接,但我无法真正理解内连接 SQL 语法的语法。 This are the structure of the 2 tables:这是2个表的结构:

attendance = EmpID, Date, TimeIn, LunchOut, LunchIn, TimeOut
actualot = EmpID, Date, TimeIn, TimeOut, Overtime

I need to join them in calendar table so that the missing dates will be seen also, this is my expected result:我需要将它们加入日历表中,以便也可以看到缺少的日期,这是我的预期结果:

result = Date, TimeIn, LunchOut, LunchIn, TimeOut, Overtime

Where date will be taken from calendar that should be equals to date of attendance with a given range like 2015-08-01 to 2015-08-30 and the Overtime is euqal to the id of attendance while the attendance is eual to the id of a given user id like 01450015. Note that i put each a auto increment primary key and the only related to each of them was the empid that is not a unique or primary key.从日历中获取的日期应等于出勤日期,给定范围如 2015-08-01 至 2015-08-30,并且加班时间等于出勤 ID,而出勤时间等于出勤 ID给定的用户 ID,如 01450015。请注意,我为每个用户添加了一个自动增量主键,唯一与每个用户相关的是 empid,它不是唯一键或主键。

This is an example based on having a Calendar table:这是一个基于日历表的示例:

SELECT C.Date, <additional columns>
FROM Calendar C LEFT OUTER JOIN
Attendance D ON C.Date = D.Date LEFT OUTER JOIN
ActualOT A ON D.EmpID = A.EmpID

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM