mysql别名和表的字段名重复的情况下,怎么使用group by

select floor((year(now()) - year(birthday)) / 10) as name, count(0) as value from user where birthday is not null group by name

这是个统计的sql,user表中有name字段,我统计的统一返回的实体类,是用name和value两个字段来接收统计结果的

group by 我不想又写那么一长串,想直接用别名name代替,但是user表中也有name,此时他会用表中的name作为group by条件,而不是我select里面的别名为name的那一串

有没有办法让group by 用我取别名的name,而不是用表中的name

那就不要用name做别名了呗

select name1 as name,value from (select floor((year(now()) - year(birthday)) / 10) as name1, count(0) as value from user where birthday is not null group by name1) t