有一个共同的架构,有两个表。
users
表包含id
,name
列。
checkins
表包含user_id
,checkin_date
列。
在此假设中,users
可以在checkins
表中包含许多行实例。
checkin_date
的类型为date
我希望能够查询签到表中至少有1次签到的所有用户,签入表是在2016年之后签到的。
答案 0 :(得分:1)
我建议使用exists
:
select u.*
from users u
where exists (select 1
from checks c
where c.user_id = u.id and c.checkin_date >= '2016-01-01'
);