select *
from user inner join
(select login_id from account where created_time >='xxx') t1
on t1.login_id = user.id;
1
krixaar 2022-02-17 15:07:29 +08:00
django 不能 id__in 么
|
2
Aganzo 2022-02-17 15:09:22 +08:00
user_ids = Account.objects.filter(created_time__gt='xxx').values_list('login_id',flat=True).distinct()
User.objects.filter(id__in=user_ids) 应该是这个意思吧,queryset 会自动以子查询形式嵌套 |
3
riiygh 2022-02-17 15:19:18 +08:00
没有看到你的 model 。假设 account 有外键 user ,可以这样试试:User.objects.filter(account__created_time__gte='xxx').all()
|
4
wuwukai007 OP |
5
krixaar 2022-02-17 16:59:51 +08:00
@wuwukai007 #4 2 楼写法等同于
select * from user where id in (select login_id from account where created_time >= 'xxx') |