gpt4 book ai didi

mysql - 选择行,除非值被另一行取消

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

FROM    TO     TYPE   
---- ---- ----
John Jane Like
Jill Jane Like
Jane John Hide

我将如何编写这样的 SELECT 语句:

SELECT * FROM table WHERE to='Jane' UNLESS from='Jane' AND type='hide'

在上表中,它将返回 John 和 Jill,减去 John,因为 Jane 选择隐藏 John,这意味着只会返回 Jill。

最佳答案

使用不存在:

select t.*
from t
where t.to = 'Jane' and
not exists (select 1
from t t2
where t2.from = t.to and t2.type = 'Hide'
);

关于mysql - 选择行,除非值被另一行取消,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44860861/

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