1

我有以下查询:

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)

任何想法?

提前致谢。

4

2 回答 2

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
于 2012-08-03T00:27:44.447 回答
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;
于 2012-08-03T00:28:50.183 回答