mysql5.7实现ROW_NUMBER()

参考 https://blog.csdn.net/subaiqiao/article/details/130305728
https://blog.csdn.net/shen_xbo/article/details/120451733

单纯分组的话,就按照下面的模板来,一定要设置初始值

select 
id,
    (@i := case when @mno = a.id then @i + 1 else 1 end) as rn,
	@mno := a.id
    
from table as a, (select @i = 0, @mno = null) sortTable

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