如何通过在 Yii 中执行此查询来获取数组?
SELECT `sevrity_id`,COUNT(*) FROM `Incident` GROUP BY `sevrity_id`
我需要一个这样的数组:array(1=>20,2=10,3=12)
如何通过在 Yii 中执行此查询来获取数组?
SELECT `sevrity_id`,COUNT(*) FROM `Incident` GROUP BY `sevrity_id`
我需要一个这样的数组:array(1=>20,2=10,3=12)
public function getSevrityCounts()
{
$data = array();
$command = Yii::app()->db->createCommand('SELECT sevrity_id,COUNT(*) AS num FROM Incident GROUP BY sevrity_id');
foreach($command->queryAll() as $row) {
$data[ $row['sevrity_id'] ] = $row['num'];
}
return $data;
}