1. 計算用戶排名最高效的方法
例如:通過用戶分享個數排名,那么自己的排名就是:比自己分享數多的用戶個數 + 1
select count(*) + 1 as count from top where `status`= 0 and `day` = '144022222' and `count` > '自己分享個數'
缺點:當多個用戶分享個數相同的時候,會出現排名相同的情況
2. MySQL 下面沒有RowNum,排序后序號卻無法得到,比較麻煩!
在網上找了再三,通過比較,確認了以下的方法是可行的 :
SELECT @rownum:=@rownum+1 rownum, CollectSn From (SELECT @rownum:=0,bbgmain.* FROM qbdb.bbgmain WHERE collectsn!='' ORDER BY collectsn limit 10) t
按照點擊數排序,查詢new表里的文章排名
select * from ( select @rank:=@rank+1 as rank, id, title from (select @rank:=0, news.* from news order by dian_num desc) rank) news_rank where id = 4;
