分组查询 每组最高的某条记录

需求是 查询每个班 年龄最小的那个人 ,需要显示如下:

SQL 语句如下:

select id,
SUBSTRING_INDEX(GROUP_CONCAT(age order by age),',',1) as age,
SUBSTRING_INDEX(GROUP_CONCAT(username order by age),',',1) as userName
from person
GROUP BY id

猜你喜欢

转载自www.cnblogs.com/refuge/p/9061383.html
今日推荐