假设我有 2 个数据库表:
table B
是一组人,table A
是table B
中的一组人
Table A = (no, id, date) no is PK, id refer to table B
Table B = (id, name) id is PK
我的目标是获取在给定日期未参加的人(id 和姓名)的数据(例如今天)这个理论看起来很简单,一组 B 减去一组谁参加了(今天),但我如何在 SQL 查询中执行此操作?我考虑用第二个查询减去第一个查询,但感到困惑。
最佳答案
select * from b where
not exists (select no from A where A.id=B.id and date=@yourdate)
关于sql - 两个查询之间的减法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12004059/