以下是我的注册信息:
Table_Trainee_Corporate_Info
Corporation_Trainee_Id TraineeId BatchId Name Mobile
261 COP000261 63 ankitha1 9555962321
262 COP000262 63 ankitha2 9555962322
264 COP000264 63 ankitha4 9555962324
265 COP000265 63 ankitha5 9555962325
266 COP000266 63 ankitha6 9555962326
267 COP000267 63 ankitha7 9555962327
268 COP000268 63 ankitha8 9555962328
263 COP000263 63 ankitha3 9555962323
以下是我的每日出勤日志表:
Table_Trainee_Attendance_Info
Trainee_atten_logId Corporation_Trainee_Id BatchId Attendance AttendanceDate
1 261 63 Present 12-09-2019 15:31
2 262 63 Present 12-09-2019 15:31
3 264 63 Present 12-09-2019 15:31
4 265 63 Present 12-09-2019 15:31
5 261 63 Present 12-10-2019 15:34
我想要一个如下所示的输出;根据两个表的Corporation_Trainee_Id,今天的日期中有多少空值以及今天的日期中有多少空值。
Corporation_Trainee_Id Name Mobile Attendance
261 ankitha1 9555962321 Present
262 ankitha2 9555962322 NULL
263 ankitha3 9555962322 NULL
264 ankitha4 9555962323 NULL
265 ankitha5 9555962323 NULL
266 ankitha6 9555962324 NULL
267 ankitha7 9555962324 NULL
268 ankitha8 9555962325 NULL
您需要在此处加入左连接:
SELECT
ci.Corporation_Trainee_Id,
ci.Name,
ci.Mobile,
CASE WHEN ai.Corporation_Trainee_Id IS NOT NULL THEN 'Present' END AS Attendance
FROM Table_Trainee_Corporate_Info ci
LEFT JOIN Table_Trainee_Attendance_Info ai
ON ci.Corporation_Trainee_Id = ai.Corporation_Trainee_Id AND
CAST(ai.AttendanceDate AS date) = CAST(GETDATE() AS date) AND
ai.BatchId = 63
WHERE
ci.BatchId = 63
ORDER BY
ci.Corporation_Trainee_Id;
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。