我正在尝试显示
的人员列表案例1:
Forgotton办理登机手续并出席
案例2:
今天缺席的人今天无法办理登机手续。
在这两种情况下,签到都将为空,因为两者都没有签到
这是我迄今取得的成就
SELECT
u.id,
u.`firstname` AS 'Firstname',
u.`lastname` AS 'Lastname',
ulr.leave_status AS 'Leave Status',
ulr.leave_from AS 'Leave From',
ulr.leave_to AS 'Leave To',
ulr.leave_description AS 'Leave Description',
DATE_FORMAT(
ulr.leave_from,
'%Y-%m-%d'
) AS 'Today''s Date'
FROM
users u
INNER JOIN users_leave_request ulr ON u.id = ulr.user_id
INNER JOIN checkin_checkout cc ON u.id = cc.users_id
WHERE
DATE_FORMAT(
leave_from,
'%Y-%m-%d'
) = CURDATE()
AND cc.checkin_time IS NULL
users_leave_request
表:table1
checkin_checkout
表:table2
答案 0 :(得分:0)
此查询将选择今天未签入的所有用户,如果他们在users_leave_request
中有记录,则还将返回该记录的数据。
通过使用LEFT JOIN
,我们避免为未在users_leave_request
中输入的签到用户返回空结果。如果我们使用JOIN
,则只有在users
和users_leave_request
表中找到记录时才会返回结果。
SELECT
u.id,
u.`firstname` AS 'Firstname',
u.`lastname` AS 'Lastname',
ulr.leave_status AS 'Leave Status',
ulr.leave_from AS 'Leave From',
ulr.leave_to AS 'Leave To',
ulr.leave_description AS 'Leave Description',
DATE_FORMAT(
ulr.leave_from,
'%Y-%m-%d'
) AS 'Today''s Date'
FROM users AS u
LEFT JOIN users_leave_request ulr ON u.id = ulr.user_id
WHERE u.id NOT IN (
SELECT u.id
FROM
users u
INNER JOIN checkin_checkout cc ON u.id = cc.users_id
WHERE
DATE_FORMAT(cc.checkin_time, '%Y-%m-%d') = CURDATE()
)