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:

  1. the top 10 users points
  2. 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

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -

PostgreSQL 9.x - pg_read_binary_file & inserting files into bytea -