如何在yii中使用MAX函数

时间:2014-09-12 06:52:43

标签: php mysql yii

Mysql MAX函数无法使用yii中的select函数

    $command = Yii::app()->db->createCommand()
    ->select("MAX(modified_date) AS MDATE,storage_path")
    ->from("engine4_storage_files")
    ->where("user_id=:user_id AND type='thumb.normal'", array(':user_id'=>$user_id))
    ->queryRow();
    print_r($command);
    exit;

请帮帮我

由于

1 个答案:

答案 0 :(得分:0)

try this example:
$model = new Model;
$criteria=new CDbCriteria;
$criteria->select='max(column) AS maxColumn';
$row = $model->model()->find($criteria);
$somevariable = $row['maxColumn'];

您也可以按照此参考:

http://www.yiiframework.com/forum/index.php/topic/6730-how-can-i-use-max-in-find-method/page_view_findpost_p_80659