On Oct 30, 2007, at 6:58 PM, Kad Kerforn wrote:> I have a table ''posts'' , each record has 2 fields
''post_count'' and
> ''post_value''
>
> I would like to find all records, sorted on the calculated ratio
> value:
> ''post_value'' / ''post_count''
>
> I am using MySQL 5 so I could use a stored procedure, but how can I
> sort
> on the calculated value ,
>
> can I write something like :
>
> Post.find( :all, :select => [''post_count'',
''post_value'',
> ?calculated_value?], :order => ?calculated_value?)
>
> thanks for your suggestions
>
> kad
Yes, almost exactly like that:
Post.find(:all, :order => ''post_value/post_count'')
-Rob
Rob Biedenharn http://agileconsultingllc.com
Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---