我有以下查询:
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)
有什么想法吗?
提前致谢。
杨
答案 0 :(得分:1)
将其包装在子查询中并再次计算记录
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
答案 1 :(得分:0)
SELECT COUNT(*) FROM (SELECT id, COUNT(*) c FROM hr WHERE time >= '2011-11-8 00:00:00' AND time <= '2011-12-9 23:59:59' GROUP BY id) counts WHERE counts.c > 3;