title: Yii2 - getting sum of a column
body: <p>I found this in the guide, but have no idea how to implement the same</p>
  
  <p><code>yii\db\Query::count();</code> returns the result of a COUNT query. Other
  similar methods include <code>sum($q)</code>, <code>average($q)</code>, <code>max($q)</code>, <code>min($q)</code>, which
  support the so-called aggregational data query. <code>$q</code> parameter is mandatory
  for these methods and can be either the column name or expression.</p>
  
  <p>Say for example I have a table name 'billing' with columns:</p>
  
  <pre><code>name     amount
  charge1  110.00
  charge2  510.00
  Total -  620.00
  </code></pre>
  
  <p>How I implement using</p>
  
  <pre><code>yii\db\Query::sum('amount');
  </code></pre>
  
  <p>I have also  tried like</p>
  
  <pre><code>$command = Yii::$app-&gt;db-&gt;createCommand("SELECT sum(amount) FROM billing");
  
  yii\db\Query::sum($command);
  </code></pre>
  
  <p>but page generates error.</p>
  
  <p>Thanks. </p>