I used this in case of integer value
$max = Yii::app()->db ->createCommand("SELECT MAX(TableCol) FROM tableName") ->where('cond1=:cond1', array(':cond1'=>$cond1)) ->andWhere('cond2=:cond2', array(':cond2'=>$cond2)) ->queryScalar();
OR
This case I used in the case of dateTime
$maxAnsTime = Yii::app()->db ->createCommand("SELECT tableColumn FROM tableName ORDER BY tableColumn DESC LIMIT 1") ->where('cond1=:cond1', array(':cond1'=>$cond1)) ->queryRow();
$ max varible will give you maximum results.
You can also use the binding parameter and put the where clause in your createCommand.
I also found that active yii records are not the best things used for a larger dataset.
source share