[英]How to get absent user list in mysql..?
我有如下表格
employees
-----------------------
empId Name MobileNumber
1 Name1 12345
2 Name2 123456
3 Name3 1234567
4 Name4 12345678
attendance
-------------------------------------------
Id MobileNumber Type attendance_datetime
1 12345 IN 2017-05-31 10:04:42
2 123456 IN 2017-05-31 10:05:29
3 1234567 IN 2017-05-31 10:06:15
4 12345 OUT 2017-05-31 18:05:15
5 123456 OUT 2017-05-31 18:10:15
6 1234567 OUT 2017-05-31 18:15:15
我想獲取特定日期的缺席用戶列表如何獲取?
我試過下面的查詢,但沒有得到結果。
select * from employees e,attendance a where e.MobileNumber = a.MobileNumber AND DATE(a.attendance_datetime) = str_to_date('31-05-2017', '%d-%m-%Y')
您需要使用左外連接:
SELECT * FROM employees e
LEFT JOIN attendance ON employees.MobileNumber = attendance.MobileNumber
AND DATE(attendance_datetime) = '2017-05-31'
WHERE attendance.Id IS NULL
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.