题解 | #为什么having后可以使用select定义的#
学生数不大于2的学校的学生情况
https://www.nowcoder.com/practice/183822a9122642c491c61ec4d479fddb
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的扩展。