检查 table 内的条件可能是自连接?
Check condition within table possibly self-join?
我有一个包含很多列的 users table 但是我正在尝试使用以下 2 列来获取用户没有过期 = 1
查询应该 return 只有用户 2。非常感谢任何帮助。
user_id expired
1 1
1 0
2 0
2 0
3 1
您可以使用 not in
执行此操作,如下所示:
select * from users where user_id
not in(select distinct user_id from users where expired = 1);
我知道你有答案,但如果你只是在寻找单个 user_id 的列表,这可能会更有效一些:
select user_id
from users
GROUP BY user_id
having MAX(expired) = 0
我有一个包含很多列的 users table 但是我正在尝试使用以下 2 列来获取用户没有过期 = 1
查询应该 return 只有用户 2。非常感谢任何帮助。
user_id expired
1 1
1 0
2 0
2 0
3 1
您可以使用 not in
执行此操作,如下所示:
select * from users where user_id
not in(select distinct user_id from users where expired = 1);
我知道你有答案,但如果你只是在寻找单个 user_id 的列表,这可能会更有效一些:
select user_id
from users
GROUP BY user_id
having MAX(expired) = 0