我想在MySQL
中实现
select * from (
select *, row_number() over (partition by uid order by last_login desc) as rn
from test)
where rn = 1
然后我发现了一个神奇的SQL,如下所示:
select * from test as a
where typeindex = (select max(b.last_login)
from test as b
where a.uid = b.uid);
它可以满足我的要求,并且效率很高,但是我很难理解此查询的过程,尤其是子查询中的where a.uid = b.uid
。
任何机构都可以简要介绍一下此查询的工作方式吗?感谢您的提前帮助。