这很管用。

SET @postrownum = 0, @postrank = 1, @postprev_val = NULL, @postprev_postnum = NULL;

SELECT @postrownum := @postrownum + 1 AS row,
@postrank := IF(@postprev_val!=postcount,@postrownum,@postrank) AS postrank,
c.user_id,
@postprev_postnum := IF(@postprev_val!=postcount,@postprev_val-postcount,@postprev_postnum) as morepost,
@postprev_val := postcount as postcount,
postcount*5 as postpoint from

(
select user_id,count(user_id) as postcount from post group by user_id order by postcount desc) as c

这不管用
SET @postrownum = 0, @postrank = 1, @postprev_val = NULL, @postprev_postnum = NULL;

select id,postrank,morepost,postcount,postpoint from user as a left join

(SELECT @postrownum := @postrownum + 1 AS row,
@postrank := IF(@postprev_val!=postcount,@postrownum,@postrank) AS postrank,
c.user_id,
@postprev_postnum := IF(@postprev_val!=postcount,@postprev_val-postcount,@postprev_postnum) as morepost,
@postprev_val := postcount as postcount,
postcount*5 as postpoint from

(
select user_id,count(user_id) as postcount from post group by user_id order by postcount desc) as c) as b on a.id=b.user_id

morepost会带着[BLOB-1B]回来,很奇怪。有人能帮忙吗!

最佳答案

奇怪,问题是这个。
@postprev_postnum=空;
我开始
@postprev_postnum=0;
它适用于第二个代码。
不明白你为什么。

10-08 04:41