2017-07-01 9 views
1
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だけが返されるということだ。

答えて

3

使用not exists

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' 
       ); 
+0

私はあなたが '意味だと思うt2.to = t.from' –