MySQL使用group by选择查询中的总行数
我需要知道查询的总结果,我使用的是COUNT() 问题是,在这个查询中,我有一个groupby 我得到的结果是5行,每行的结果总数为5行MySQL使用group by选择查询中的总行数,mysql,Mysql,我需要知道查询的总结果,我使用的是COUNT() 问题是,在这个查询中,我有一个groupby 我得到的结果是5行,每行的结果总数为5行 SELECT COUNT(c.id) AS tot FROM contributors AS c LEFT JOIN contributors_info AS ci ON c.id = ci.idcontributor WHERE c.state = 'active' GROUP BY c.id ORDER BY c.id ASC
SELECT COUNT(c.id) AS tot
FROM contributors AS c LEFT JOIN contributors_info AS ci
ON c.id = ci.idcontributor
WHERE c.state = 'active'
GROUP BY c.id
ORDER BY c.id ASC
我的查询结果是
|c.id|
| 1 |
| 2 |
| 1 |
| 1 |
| 1 |
|c、 身份证|
| 1 |
| 2 |
| 1 |
| 1 |
| 1 |
尝试下面的查询
SELECT COUNT(*) as tot FROM(
SELECT c.id
FROM CONTRIBUTORS AS c LEFT JOIN contributors_info AS ci
ON c.id = ci.idcontributor
WHERE c.state = 'active'
GROUP BY c.id
ORDER BY c.id ASC
) AS tmp
您的查询工作正常,现在是否比使用SQL\u CALC\u FOUND\u行更快?