人(id,狗)
我如何找到养狗最多的人
select *
from person p1
where p1.id in (
select p2.id
from person p2
where p1.id = p2.id
having count(dogs > (
select p3.id ...etc
我走在正确的轨道上还是行不通? 感谢您的浏览
最佳答案
这个怎么样?
select *
from person
where dogs = (select max(dogs) from person)
可能不是最有效的方法,但这将为您提供拥有最多狗数量的人(或多人)。如果您只想要其中之一,可以这样做:
select top 1
from person
order by dogs desc
关于SQL找人条目狗最多,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3433851/