As If To Add Criteria?

In a conditional use mysql to do so

SELECT IF (data> 2, data, 3) WHERE status = 1

As you can add if (data> 2, data, 3) criteria?

I don’t understand the question, can you try to restate it?

As an aside, in MySQL, you can use GREATEST():

SELECT GREATEST(data, 3) WHERE status = 1

Think this will work.


  'select' => ['IF(data>2, data, 3) AS data'],

  'condition' => 'status=1'


If that’s the idea, I’ll try it and see if it works.


class Mytest extends CActiveRecord


public $newdata;



$criteria=new CDbCriteria;

$criteria->select = array("*"," if(data > 2, data, 3) AS newdata");




It’s work…