Thinkphp 下 MySQL group by 接count 获得条数方法

 比如 下面的语句 , 用于分组统计

select count(*) from es_diabetes where uid=43658 GROUP BY uniques 

结果明显不是我们想要得,为什么呢,因为这是个group up分组

改为下面的,先去重 , 再分组

select count(DISTINCT uniques ) from es_diabetes where uid=43658

 

group by 是分组,不能直接用于 count 统计

但是select还是可以的

或者 可以使用 子查询 

SELECT count(*) AS c FROM(SELECT count(*) FROM es_diabetes where uid =43658 GROUP BY uniques ) as s

结果还是一样的

posted @ 2017-05-10 11:25  freedom/cn  阅读(5338)  评论(0编辑  收藏  举报