如何从特定日期在另一个表中不存在的一个表中获取ID [英] how get id from one table which does not exists in another table on specific date

查看:61
本文介绍了如何从特定日期在另一个表中不存在的一个表中获取ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从出勤系统表中获取ID,但该ID在特定日期不存在,这意味着该日期没有输入.
我如何从该日期的注册表中获取ID

i want get id from table for attendance system which is not present on specific day means doesn`t have entry to that day.
how do i get id from registration table for that date

推荐答案

我认为Sql Server的NOT IN子句与Sub Query一起可以用于上述内容目的如下

I think the NOT IN Clause of Sql Server in conjunction with Sub Query can be used for the above purpose as below

SELECT Id 
FROM RegistrationTable
WHERE Id NOT IN (
    SELECT Id 
    FROM AttendanceTable
    WHERE Date = --Enter Required Date literal or variable here
)


如果RegistrationTable包含来自AttendaceTable的PK(主键)的FK(外键),请尝试以下操作:
If RegistrationTable contains FK (Foreign Key), which comes from AttendaceTable as a PK (Primary Key), try this:
SELECT RT.RegistrationID
FROM RegistrationTable AS RT LEFT JOIN AttendanceTable AS AT ON RT.AttendanceID = AT.AttendanceID
WHERE NOT RT.Date IS NULL AND AT.Date IS NULL
--or any other value


这篇关于如何从特定日期在另一个表中不存在的一个表中获取ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆