MySQL row_number() and 5.6 version do not support row_number() function method

There is no problem with using row_number() locally, but when you go to the server to query the data, you can’t find the query, because the server version of mysql is 5.6, and the row_number() function is temporarily not supported, but you need to group users to sort by time to get the numbers. data. The solution is as follows

-- mysql自带的row_number()的分组内排序
select *,row_number() over(partition by userID order by date desc) from  aa;

-- 解决方案
select (@i :=case when @userID= userID then @i + 1 else 1 end ) as rownum,p.*,(@userID:= userID)
FROM aap,(select @i := 0 )as a
GROUP BY userID,id
order by userID

Guess you like

Origin blog.csdn.net/zhongzih/article/details/112528301