title: Complex query with query builder in Laravel 5
body: <p>I have 3 tables,</p>
  
  <p><code>subscribers</code>:</p>
  
  <p><a href="https://i.stack.imgur.com/syCAB.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/syCAB.png" alt="enter image description here"></a></p>
  
  <p><code>subscribers_lists_subscribers</code>:</p>
  
  <p><a href="https://i.stack.imgur.com/mJZCC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mJZCC.png" alt="enter image description here"></a></p>
  
  <p>And <code>subscribers_lists</code>:</p>
  
  <p><a href="https://i.stack.imgur.com/ESeZC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ESeZC.png" alt="enter image description here"></a></p>
  
  <p>I am trying to have a query like this:</p>
  
  <pre><code>$baseQuery = DB::table('subscribers_lists')
      -&gt;leftjoin('subscribers_lists_subscribers', 'subscribers_lists.id', '=', 'subscribers_lists_subscribers.subscribers_list_id')
      -&gt;leftjoin('subscribers',  'subscribers_lists_subscribers.subscriber_id', '=', 'subscribers.id')
      -&gt;select(
          'subscribers_lists.id as count_clickers',
          DB::raw('count(subscribers_lists_subscribers.subscribers_list_id where subscribers.status = "Active") as count_active')
          'subscribers_lists.updated_at as last_activity'
      )
      -&gt;groupBy('subscribers_lists.id');
  </code></pre>
  
  <p>I need to have this:</p>
  
  <pre><code>where subscribers.status = "Active"
  </code></pre>
  
  <p>I am getting an error, can anyone tell me what I am doing wrong?</p>