MySql order by count(*)

mjqavswn  于 2023-04-28  发布在  Mysql
关注(0)|答案(1)|浏览(113)

该任务是一个国家的名单,有超过10个客户我试图只显示的价值观,计数〉10在表中
我试过这个,但它没有过滤表:

select co.country, count(*) from sakila.country as co
inner join city as ci on co.country_id = ci.country_id
inner join address as ad on ci.city_id = ad.city_id
inner join customer as cu on cu.address_id = ad.address_id
group by co.country
order by count(*) > 10;
2nbm6dog

2nbm6dog1#

通过只显示计数大于10的值,您需要使用havinghaving需要使用,当你想过滤聚合函数的结果时,e.g.计数、求和。

select co.country, count(*)
from sakila.country as co
inner join city as ci on co.country_id = ci.country_id
inner join address as ad on ci.city_id = ad.city_id
inner join customer as cu on cu.address_id = ad.address_id
group by co.country
having count(*) > 10;
order by count(*);

如果您仍然希望按计数排序结果,您仍然需要在en中设置order by

相关问题