mysql数据库如何进行数据分组统计呢?


摘要:
下文讲述mysql数据库中数据分组统计的方法分享,如下所示;

实现思路:
   方式1.直接使用group by 对数据表进行分组聚合操作

   方式2.使用group by 结合case when对数据表进行分组聚合操作
select count(*) as qty,typeA,typeB
    from `maomao365.com` group by typeA,typeB
 
select sum(
    case when type ='A' then qty else 0
  ) as typeAQty,
      sum(
        case when type ='B' then qty else 0
       ) as typeBQty,
     sum(
    case when type ='C' then qty else 0
  ) as typeCQty     
    from `maomao365.com` group by type