Book.find(:all, :conditions=>["release_date >= ? and release_date < ? and book_type=''New''",@date[:from],@date[:to]], :group=>"auther_id", :order=>"count(*) desc", :select=>"auther_id,sum(case when auther_type = ''New'' "+ "then 1 else 0 end) as new,sum(case when auther_type != ''New'' then 1 else 0 end) as review,count(*) as total") in the above query how to write the "case" conditions in ruby query. can anyone tell me which is the equivalent ruby syntax for this sum(case when auther_type != ''New'' then 1 else 0 end) as review thanks in advance Jk -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Dec 30, 10:04 am, rails and rails only <rails-mailing-l...@andreas- s.net> wrote:> Book.find(:all, > :conditions=>["release_date >= ? and release_date < ? and > book_type=''New''",@date[:from],@date[:to]], > :group=>"auther_id", > :order=>"count(*) desc", > :select=>"auther_id,sum(case when auther_type = ''New'' "+ > "then 1 else 0 end) as new,sum(case when auther_type != ''New'' then > 1 else 0 end) as review,count(*) as total") > > in the above query how to write the "case" conditions in ruby query.You can''t - there are no helpers for generating complex select statements like that. Fred> > can anyone tell me which is the equivalent ruby syntax for this > > sum(case when auther_type != ''New'' then 1 else 0 end) as review > > thanks in advance > Jk > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Dec 30, 10:10 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Dec 30, 10:04 am, rails and rails only <rails-mailing-l...@andreas- > > s.net> wrote: > > Book.find(:all, > > :conditions=>["release_date >= ? and release_date < ? and > > book_type=''New''",@date[:from],@date[:to]], > > :group=>"auther_id", > > :order=>"count(*) desc", > > :select=>"auther_id,sum(case when auther_type = ''New'' "+ > > "then 1 else 0 end) as new,sum(case when auther_type != ''New'' then > > 1 else 0 end) as review,count(*) as total") > > > in the above query how to write the "case" conditions in ruby query. > > You can''t - there are no helpers for generating complex select > statements like that. >To clarify, there aren''t any builtin things. There might be a third party plugin that does this. Fred --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---