您的位置:首页 > 数据库 > MySQL

mysql count group by统计条数方法

2017-01-11 18:03 323 查看
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: