Mysql partition by

一,看原表

select * from `user`;

Mysql partition by_第1张图片

二,查询同组年级最大的

select 
username
,SUBSTRING_INDEX( GROUP_CONCAT(age order by age desc) ,',',1) uuid 
from 
(
    select uuid
	,username
	,`password`
	,age
    from `user`
)b 
GROUP BY uuid asc;

Mysql partition by_第2张图片

第二种:

select  *
from user
where (CreateTime,userId) in 
	  (select max(CreateTime),userId from user group by userId);

你可能感兴趣的:(SQL,mysql,数据库)