gpt4 book ai didi

mysql select 匹配多行

转载 作者:行者123 更新时间:2023-11-29 01:04:07 25 4
gpt4 key购买 nike

我有一张看起来像的 table 。

user    project
---- -------
bob news
bob theatre
sarah news
fred news
fred fred
fred movies
sarah movies

如果用户从不 fred

,我将尝试提取项目列表

所以根据上表得出的结果就是。

bob theatre 

我对如何实现这一目标感到困惑。我在可以加入的另一个表中有一个唯一的用户列表。我可以用某种语言的 for 循环来做到这一点,但我认为必须有一种方法可以在 native sql 中做到这一点。

最佳答案

select distinct a.* 
from mytable a
left join mytable b on b.project = a.project and b.user = 'fred'
where b.user is null

对于您想要的行,不会有一个连接行,并且这些行将具有 null 值,因此 where 子句只过滤掉那些。

关于mysql select 匹配多行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12965709/

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