title: Yii How to optimize a sum() query
body: <p>I want to skip the <code>foreach</code> loop;</p>
  
  <p>How can I get the <code>sum</code> by using a yii query?</p>
  
  <pre><code>$sql = 'select size_kb from comp_arch_stats where company_id = ' . ($model-&gt;company_id) . ' and arch_month = ' . $month . ' and arch_year = ' . $year . ';';
          $val = Yii::app()-&gt;db-&gt;createCommand($sql)-&gt;queryAll();
          $sum = 0;
          foreach ($val AS $result) {
              $sum += $result['size_kb'];
          }
  </code></pre>