在做项目中,难免遇到这些逻辑,记录下来
表tablea,以groupid分组,取sortid最大的一条数据
select a.* from tablea as a where not exists(select 1 from tablea as b where a.groupid=b.groupid and (a.sortid=b.sortid and a.id<b.id or a.sortid<b.sortid))
在做项目中,难免遇到这些逻辑,记录下来
表tablea,以groupid分组,取sortid最大的一条数据
select a.* from tablea as a where not exists(select 1 from tablea as b where a.groupid=b.groupid and (a.sortid=b.sortid and a.id<b.id or a.sortid<b.sortid))