如何显示缺席和现在
此代码仅显示存在,但我希望缺少日期结果
如果我删除WHERE a.date BETWEEN '2015-05-20' AND '2015-05-20'
然后缺席和现在的结果显示完美,但我希望选择日期
如何解决此问题请帮我解决此问题
感谢
直播示例请点此链接
http://sqlfiddle.com/#!9/9604f/2
Mysql代码
SELECT s.user_name, s.user_pass,a.date
, CASE WHEN a.user_name IS NOT NULL THEN 'Present' ELSE 'Absent' END as attendance_status
FROM users s
LEFT JOIN attend a on s.user_name=a.user_name WHERE a.date BETWEEN '2015-05-20' AND '2015-05-20'
答案 0 :(得分:1)
您需要将条件从where
移动到on
子句:
SELECT s.user_name, s.user_pass, a.date,
(CASE WHEN a.user_name IS NOT NULL THEN 'Present' ELSE 'Absent'
END) as attendance_status
FROM users s LEFT JOIN
attend a
ON s.user_name = a.user_name AND a.date BETWEEN '2015-05-20' AND '2015-05-20';
WHERE
子句将外连接转换为内连接,因为它会过滤掉NULL
值。