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
SELECT count(*) from (SELECT post_ask.ask_id,post_ask.ask_body,post_ask.ask_user,post_answer.answer_body,post_answer.answer_user from post_ask right JOIN post_answer on post_ask.ask_id = post_answer.ask_id and post_answer.answer_body is not null where post_ask.ask_id
is not null and post_ask.ask_body <>'' GROUP BY post_ask.ask_id ) as u