我有以下查询:
select count(*) c , id
from hr
where time >= '2011-11-8 00:00:00' and
time <= '2011-12-9 23:59:59'
group by id
having c>3;
结果列表可能非常庞大(有时多达 10,000 项),我不想列出所有项目,因为我只想获取总数。除了“select found_rows()”,我试图找到一个 sql 语句来完成工作而不打印列表。 (我没有使用 Perl、PHP 或任何其他 API,仅使用 sql)
有什么想法吗?
提前致谢。
杨
最佳答案
将其包裹在子查询中并再次统计记录
SELECT COUNT(*) totalCount
FROM
(
select count(*) c , id
from hr
where time >= '2011-11-8 00:00:00' and
time <= '2011-12-9 23:59:59'
group by id
having COUNT(*) > 3
) x
关于MySQL:分组统计后得到总查询数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11787622/