我有两个故事(MySql)员工和daily_attendance,在daily_attendance中我试图保存 每位员工的每日出勤率。我在daily_attendance表中有以下列:
sno, (primary key)
emp_sno, (sno from employees table primary key in employees table)
prj_sno,
emp_sup_sno,
duty_status,
duty_year,
duty_month,
reason,
duty_day,
is_current
我需要显示一个出勤表单,用户可以通过点击“A”缺席或“P”出现单选按钮来保存daily_attendence表中的每日出勤率。 用户应该只需要查看那些在选定的年,月和日中尚未保存的员工。为此我写了以下查询,但它不适合我。
SELECT * FROM employees e
LEFT JOIN daily_attendance d
ON e.sno = d.emp_sno
WHERE d.emp_sno IS NULL AND d.duty_year = '2013' AND d.duty_month = '1'
AND d.duty_day = '1'
AND d.is_current = 1
现在,我不确定这是向所有员工列表显示尚未在daily_attendance表中添加的出勤率的好方法吗?
请帮帮我。提前谢谢
答案 0 :(得分:2)
以这种方式试试
SELECT e.*
FROM employees e LEFT JOIN daily_attendance d
ON e.sno = d.emp_sno
AND d.duty_year = '2013'
AND d.duty_month = '1'
AND d.duty_day = '1'
AND d.is_current = 1
WHERE d.emp_sno IS NULL