假设我看了不止一部电影,我如何找到所有看过我看过的所有电影的人呢?
MovID Name Movie name
---------------------
1 | me |Batman
2 | me |Spider Man
1 | Jason |Batman
2 | Jason |Spider Man
3 | Jason |King kong
3 | Jim |King kong
4 | Jim |Titanic
结果应该给我杰森。谢谢!
答案 0 :(得分:1)
这是一种方式:
select name
from tbl
where movid in (select movid from tbl where name = 'me')
and name <> 'me'
group by name
having count(*) = (select count(*) from tbl where name = 'me')