`

浅谈group by和distinct

阅读更多

        group by和distinct只了去重意义一样,但是group by应用范围更广泛些,如分组汇总或者从聚合函数里筛选数据等。

        譬如:统计每id数并且只显示数大于3

select id ,count(id) from table_name group by id having count(*)>3;

       distinct做不到。

       另外,因distinct会导致全表扫描而group by索引建的恰当的话,会有性能上提高。

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics