title: select number of records using join on three tables using single query
body: <p>I have Group model , User model , Ticket model </p>
  
  <p>Group has_many_and_belongs_to users and user has_many tickets </p>
  
  <pre><code>**Groups**
  
  id | name | user_id
  
  **User**
  
  id | name | group_id
  
  **Ticket**
  
  id | title | group_id | user_id
  </code></pre>
  
  <p>I want to retrieve count on tickets of user belonging to specific group on </p>
  
  <p>particular time of intervals</p>
  
  <p>I have tried this one but didn't worked.</p>
  
  <pre><code>select t.user_id, t.group_id ,count(t.id), (select count(t.id)
  from tickets t
  where created_at &lt; current_timestamp - INTERVAL '24 hours')
  from tickets t
  LEFT OUTER JOIN groups ON g.id=t.group_id
  LEFT OUTER JOIN users u ON u.id=t.user_id 
  GROUP BY t.user_id, t.group_id;
  </code></pre>
  
  <p>How can I do this in single query?.</p>
  
  <p>Thanks</p>