我想使用Yii实现SQL的GROUP BY
子句。在这里,我面临的问题是只返回第一行而不是所有行。
$connection = Yii::app()->db;
$sql = "SELECT group_name FROM `authitem` GROUP BY group_name";
$command = $connection->createCommand($sql);
$row = $command->queryRow();
print_r($row);
$res = array();
foreach ($row as $key => $val) {
$res[] = array('label' => $key, 'value' => $val);
}
print_r($res);
答案 0 :(得分:2)
而不是
$row = $command->queryRow();
尝试这样,
$row = $command->queryAll();