gpt4 book ai didi

mysql - 如果 user_id 包含特定代码则跳过行

转载 作者:行者123 更新时间:2023-12-01 00:35:33 25 4
gpt4 key购买 nike

我有这些行

 user_id   code
1 9103
1 9103
1 9001
2 9103
3 9103
3 9104
4 9103
4 9103
4 9001

我只想获取不包含9001的id,那么就只获取2和3我尝试使用 Distinct 但我没有 lucky

Select distinct v.code, user_id from mytable as v
where v.code not in ( Select v2.code from mytable as v2
where v2.code=9001)

最佳答案

按用户分组,然后只取那些没有条件记录的组

select user_id
from your_table
group by user_id
having sum(code = 9001) = 0

关于mysql - 如果 user_id 包含特定代码则跳过行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51844170/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com