数据库中,使用group by进行分组查询然后求count(*),取出来的结果是每个分组的数量。
select count(*),sum(condition) from tableName where conditions group by condition
此时count(*)统计的是每个分组含有的记录数。
一、如果想求分组总数的可以首先创建视图,
CREATE VIEW `total_num` AS (select distinct(a.id) as id, sum(b.num) as sumNum from a, b where conditions group by condition) ;
二、
select * from total_num;
可以在页面展示total_num表中的字段信息,
框架自动计算count(*),进行分页等相关信息的计算。
注意 count(*)和group by同时使用,统计出来的是分组之后每组的记录数。