ranking entries in mysql table

后端 未结 5 1301
清歌不尽
清歌不尽 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:16

    If you are using an InnoDb table then you may consider building a clustered index on the popularity column. (only if the order by on popularity is a frequent query). The decision also depends on how varied the popularity column is (0 - 3 not so good).

    You can look at this info on clustered index to see if this works for your case: http://msdn.microsoft.com/en-us/library/ms190639.aspx

    This refers to SQL server but the concept is the same, also look up mysql documentation on this.

提交回复
热议问题