ruby on rails - Specific order (sql) -
i have got model pupil
, has got field score
. need make list strange rule: order score (desc) (!) scores more 100 should ordered zero:
pupil.all( :order => 'score desc' ...?) 100 86 34 21 6 3 1 0 143 125 354 0 456 0 0
i can order using ruby, need sql
aslo can create additional field in db storing data
new_score = score > 100 ? 0 : score
think can make sql without it
you can order 'score > 100' (order booleans), order score. score > 100 pre-ordered boolean, , sub-order order other scores after >100 ones.
i hope clear enough , looking :)
Comments
Post a Comment