select university,count(device_id) as cnt,group_concat(device_id separator ';') as device_list from user_profile group by university having cnt<=2; /* count(device_id)<=2;*/
众所周知,select 的执行顺序在having之后,其他关系型数据库都不行,但是MySQL例外。
执行和解释不是一个意思,在执行前已经有了临时表,所以可以使用别名
在MySQL5.7.5后ONLY_FULL_GROUP_BY sql mode 这个默认不开启,则可以有sql的扩展。

京公网安备 11010502036488号