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/