我有以下查询。
SET @rownum := 0;
SELECT result.rank, result.postid FROM (
SELECT CASE @rownum
WHEN 5 THEN @rownum:=1 ELSE @rownum:=@rownum + 1 END AS rank
,c.postid
FROM comments c
ORDER BY c.postid DESC
) as result
它以以下形式返回我的结果。
rank postid
---------------------------------
1 199
2 199
3 199
4 199
5 198
1 198
2 198
3 198
4 198
5 198
6 198
现在我想更新这个查询,以便根据 postid.postid 指定排名 199 将从 1 到 4 排名,一旦它识别出新的 postid 出现,它应该再次将其从 1 排名到任何数量的记录id 包含。
I want the count of rank for each postid to start from 1 and goto the number of times that postid is appearing.
编辑:
@lieven 检查这张图片仍然有问题。
如您所见,帖子已172
完成,但排名仍在继续