mysql - How to use order by clause with 2 fields with DESC in rails? -


i want toppers may happen more 1 user have same score highest score amongst them want select 1 has 1st reached score used following query not giving me correct result.
using ruby on rails technology.

top_score_cards=score.order("updated_at desc,points desc").uniq 

your order arguments need in opposite order: stands order updated @ first, , if there "tie" updated at, you'll 1 highest score. needs other way round.

also, if want people got score first, need order "updated_at asc", since return lowest time first. can "updated_at" since "asc" default.

for example highest score, (the earliest if there tie high score), with

top_score = score.order("points desc, updated_at").first 

i don't know trying uniq, , don't explain requirements well, move further forward.


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -