我正在整理一个具有排行榜概念的小应用程序.基本上,模型只是一个player_name和一个current_score.
我想要做的是获得特定玩家的排名,并且考虑到新的分数一直在进行,它需要是动态的.显然,我可以使用order by子句进行正常查找,然后我必须循环遍历每条记录.当我有100,000行时,效率不高.
我应该采取什么方法的任何建议?
以下是表的迁移:
@H_502_8@class Createscores < ActiveRecord::Migration def self.up create_table :scores do |t| t.string :player_name t.integer :current_score t.timestamps end end def self.down drop_table :scores end end编辑
举个例子,我有以下几点:
我如何计算出“唐纳德刘易斯”的排名?