MySql分组后统计数量

SELECT count(*) FROM 表名 WHERE 条件  这样查出来的是总记录条

SELECT count(*) FROM 表名 WHERE 条件 GROUP BY id //这样统计的会是每组的记录条数.

select count(*) from (select ...from .....where ......group by .....) a;


select count(*) from(

select
    IFNULL(AVG(a.price),0) currentPrice,
    a.data_time dealDate,
    gc.name className
    from ezs_price_trend a,ezs_goods_class gc,ezs_dict e1,ezs_dict e2 where e1.code like 'EZS_COLOR%' and e2.code like 'EZS_FORM%'
    and  a.goodClass_id = gc.id and a.color_id = e1.id and a.form_id = e2.id and a.type = '3'
    /*多条件查询*/
     GROUP BY DATE_FORMAT(a.data_time,'%Y-%m-%d') ORDER BY a.data_time desc

) a ;



select
    a.data_time,DATE_FORMAT(a.data_time,'%Y-%m-%d'),
    date_add(DATE_FORMAT(a.data_time,'%Y-%m-%d'),interval 1 MONTH)/*增加月份*/,
    DATE_SUB(DATE_FORMAT(a.data_time,'%Y-%m-%d'),interval 1 MONTH)/*减少月份*/
    from ezs_price_trend a
    /*多条件查询*/
     GROUP BY DATE_FORMAT(a.data_time,'%Y-%m-%d') ORDER BY a.data_time desc;

你可能感兴趣的:(MySql)