ranking entries in mysql table

后端 未结 5 1300
清歌不尽
清歌不尽 2021-02-06 12:44

I have a MySQL table with many rows. The table has a popularity column. If I sort by popularity, I can get the rank of each item. Is it possible to retrieve the rank of a partic

5条回答
  •  日久生厌
    2021-02-06 13:04

    hobodave's solution is very good. Alternatively, you could add a separate rank column and then, whenever a row's popularity is UPDATEd, query to determine whether that popularity update changed its ranking relative to the row above and below it, then UPDATE the 3 rows affected. You'd have to profile to see which method is more efficient.

提交回复
热议问题