我有查询,它将计算哪个名字在字段中有一些数字并计算重复次数。结果是具有最多计数的名称。
我现在需要将此计数限制为10或15行,但是当我设置限制时它不起作用。
Select home, count(*) as count
from (select * from results where more='33' and name='FirstName' LIMIT 10) as limit10
group by home
order by count(more) desc
LIMIT 1;
我尝试使用LEAST,但同样如此。我现在按日期添加顺序,计算exec的最后一行,但是它相同......
Select home, LEAST( count(*), 12) as count
from (SELECT *,STR_TO_DATE(date, '%d.%m.%Y') as datum FROM results where more='33' and name='FirstName' ORDER BY datum desc) as limit12
group by home
order by count(more) desc
LIMIT 1;
答案 0 :(得分:1)
我建议您使用LEAST
功能:
Select home, LEAST( count(*), 10 ) as count
from results where more='33' and name='FirstName'
group by home
order by count(more) desc
LIMIT 1;
这将获得相同的最终结果,并作为额外的奖励,你摆脱该子查询