mysql count group by统计条数方法

mysql 分组之后如何统计记录条数? gourp by 之后的 count,把group by查询结果当成一个表再count一次
select count(*) as count from
(SELECT count(*) FROM 表名 WHERE 条件 GROUP BY id ) a;

实战例子:
select 
count(*) as total 
from (select count(*) from users group by user_id) u

 

转载:流风,飘然的风,博客网站:http://www.ssqhm.com

Logo

更多推荐