假设我有一个表Person(Name, Hobby),总共有3个爱好。该表的值类似于

Amy | Stamp Collection
Kevin | Mountain Biking
Kevin | Stamp Collection
Ron | Mountain Biking


在这里,Kevin拥有爱好Mountain BikingStamp Collection。我需要编写查询以检索Kevin

我怎样才能拥有所有爱好的人?

谢谢

最佳答案

SELECT Name
FROM Person
GROUP BY Name
HAVING COUNT(*) = (SELECT COUNT(DISTINCT Hobby) FROM Person)


Runnable example

09-26 09:23