开发者社区> 问答> 正文

在两张桌子上获得今天的出席人数

以下是我的注册信息:

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

展开
收起
心有灵_夕 2019-12-10 17:48:39 729 0
1 条回答
写回答
取消 提交回答
  • 您需要在此处加入左连接:

    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;
    
    2019-12-10 17:49:33
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
回归职业教育的本质:内容为王,质量至上,赢在口碑 立即下载
回归职业教育的本质 内容为王,质量至上,赢在口碑 立即下载
女性移动App安全攻防战 立即下载