Hi, I have a query like SELECT call_queue_id,agent_id,count(*) AS count FROM completed_calls GROUP BY call_queue_id,agent_id ORDER BY call_queue_id,agent_id on a table with following structure: +-----------------+-------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-----------------+-------------+------+-----+---------+----------------+ | id | int(11) | | PRI | NULL | auto_increment | | call_queue_id | int(11) | YES | | NULL | | | agent_id | int(11) | | | 0 | | | start_time | datetime | YES | | NULL | | | end_time | datetime | YES | | NULL | | | status | char(1) | YES | | c | | +-----------------+-------------+------+-----+---------+----------------+ How can I express this query using find? Right now I am using find_by_sql, but I would like to use find because I want to use with_scope (I am assuming that with_scope will not work with find_by_sql) regards, raj --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Try: YourModelClass.find(:all, :select => "call_queue_id,agent_id,count(*) AS count", :group => "call_queue_id,agent_id", :order => "call_queue_id,agent_id") -Paul --~--~---------~--~----~------------~-------~--~----~ 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 12/28/06, Paul Corcoran <prcorcoran-Wuw85uim5zDR7s880joybQ@public.gmane.org> wrote:> YourModelClass.find(:all, :select => "call_queue_id,agent_id,count(*) > AS count", :group => "call_queue_id,agent_id", :order => > "call_queue_id,agent_id")Thanks!! That does work, but when I tried to use :include => this as well as :group stopped working. Is there a way to get this working with another table included in? raj --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Unfortunately that won''t work. Rails doesn''t support :group when an :include is specified. -Paul --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---