我在Mysql数据库中具有以下数据库架构
用户数
出勤率
现在,对于给定的日期范围,我想构建一个报告,该报告列出一个用户,以及另一列说明该日期是否存在的用户。
我正在尝试使用以下查询使用左外连接完成它
select * from users left outer join attendance on users.id = attendance.user_id where users.id in (11, 12);
如何修改上面的查询,以便我可以获取报告?
您可以使用如下查询:
select u.*,
IF(a.id IS NOT NULL, 'Present', 'Not Present') AS IsPresent
from users u
left outer join attendance a
on u.id = a.user_id and a.checked_on = ?
where u.id in (11, 12);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句