如图数据
在MySQL中排序,想要达到val倒序派列,之后根据val倒序顺序,再排列uid。
也就是把倒序val的uid放到一起。
可能描述的有点绕,仔细看下数据就明白了。
order by val desc, uid
把表名换成你的,记得采纳
select uu1.* from newtable uu1
left join (
select u1.uid,max_val,count(1) max_val_cnt
from newtable u1
join (
select uid,max(val) max_val
from newtable
group by uid
) u2
on u1.uid=u2.uid and u1.val=u2.max_val
group by u1.uid,max_val
) uu2
on uu1.uid=uu2.uid
order by max_val desc ,max_val_cnt desc,val desc