mysql - Rails - how to pull specific sorted data out of database -
i have database columns (username, points). making call return fields database use in program. want pull:
- the top 10 users points
- the 5 users above/below username requesting rankings
i can pull top 10 enough...
top_users = userpoints.find( :all, :conditions => ['points > 0'], :order => "points desc", :limit => 10)
pulling specific entry username requesting easy find_by_username, how determine user ranked? then, how go finding 5 users above , 5 users below specific user (assuming user not in top 10)?
thanks!
-mark
maybe using 2 queries?
users above current user:
userpoints.all(:conditions => ['points > ?', user.points], :limit => 5, :order => 'points asc')
users below current user:
userpoints.all(:conditions => ['points < ?', user.points], :limit => 5, :order => 'points desc')
maybe there way using single query, not sql expert, should solve you.
Comments
Post a Comment