我想这样做:
SELECT * , ROW_NUMBER() OVER (PARTITION BY Id ORDER BY score DESC, creationDate DESC) as num
FROM DB
ORDER BY score DESC, creationDate DESC
但在 MariaDB 10.1 中,row_number 不可用。我设法做到了:
SELECT *, (@num:= @num + 1) AS num
from DB,
(SELECT @num:= 0 AS num1) AS c
order by score DESC, creationDate DESC
但我不知道如何放置分区,所以我可以为任何 Id 开始一个新的计数(最终目标是按创建的 num 排序)
谢谢