group by、where、having

where:是利用数据库本来存在的数据在查询,是在group by、having之前执行。

group by:是将本来就有的数据按照条件进行分组。

having:是将数据库没有的数据,可以理解为group by后的数据,再次进行条件判断查询,在group by后执行。

例如场景查询:按手机号分组查出权限种类数大于1的手机号

select count(distinct role),mobile from 表名 group by mobile having count(distinct role) > 1;

原文地址:https://www.cnblogs.com/two-bees/p/10451633.html