过去9天内的大多数注册计数

时间:2019-05-23 17:09:42

标签: mysql

我上面的数据库中有数据

如何选择过去9天注册量最多的国家

ID NAME COUNTRY CREATED
1  JEF  UK      2019-05-19 10:10:40
2  TRO  USA     2019-05-10 15:10:30
3  BTI  UK      2019-05-05 12:10:20
4  NGU  CA      2019-05-10 14:10:10

这是我的查询

select country from user group by country order by count(*) desc and created > now() - interval 9 day

1 个答案:

答案 0 :(得分:0)

在您的查询中,WHERE子句条件已添加。将ORDER BY移至created > now() - interval 9 day子句将起作用。

查询将是:

WHERE

要获取过去9天内注册次数最多的国家/地区,请使用
SELECT country, count(*) as CountryCount FROM `user` WHERE created > now() - interval 9 day GROUP BY country ORDER BY count(*) desc ,查询将是:

ORDER BY COUNT(*) DESC LIMIT 1