title: How to count and group by in yii2
body: <p>I would like to generate following query using yii2:</p>
  
  <p><code>SELECT COUNT(*) AS cnt FROM lead WHERE approved = 1 GROUP BY promoter_location_id, lead_type_id</code></p>
  
  <p>I have tried:</p>
  
  <pre><code>$leadsCount = Lead::find()
  -&gt;where('approved = 1')
  -&gt;groupBy(['promoter_location_id', 'lead_type_id'])
  -&gt;count();
  </code></pre>
  
  <p>Which generates this query:</p>
  
  <pre><code>SELECT COUNT(*) FROM (SELECT * FROM `lead` WHERE approved = 1 GROUP BY `promoter_location_id`, `lead_type_id`) `c`
  </code></pre>
  
  <p>In yii 1.x I would've done the following:</p>
  
  <pre><code>$criteria = new CDbCriteria();
  $criteria-&gt;select = 'COUNT(*) AS cnt';
  $criteria-&gt;group = array('promoter_location_id', 'lead_type_id');
  </code></pre>
  
  <p>Thanks!</p>