Summary of common methods of Yii CDbCriteria.
$criteria = new CDbCriteria;
$criteria->addCondition("id=1"); //Query conditions, that is, where id = 1
$criteria->addInCondition('id', array(1,2,3,4,5)); //Represents where id IN (1,2,3,4,5,);
$criteria->addNotInCondition('id', array(1,2,3,4,5));//Exactly the same as the above, it is NOT IN
$criteria->addCondition('id=1','OR');//This is an OR condition. When there are multiple conditions, the condition is OR instead of AND
$criteria->addSearchCondition('name', 'category');//Search conditions actually represent. . where name like '%category%'
$criteria->addBetweenCondition('id', 1, 4);//between 1 and 4
$criteria->compare('id', 1); //This method is quite special, it will automatically process it into addCondition or addInCondition according to your parameters,
//That is, if the second parameter is an array, addInCondition will be called
/**
* Pass variables
*/
$criteria->addCondition("id = :id");
$criteria->params[':id']=1;
/**
* Some public vars
*/
$criteria->select = 'id,parentid,name'; //Represents the field to be queried, the default select='*';
$criteria->join = 'xxx'; //Join table
$criteria->with = 'xxx'; //Call relations
$criteria->limit = 10; //Get 1 piece of data, if it is less than 0, it will not be processed
$criteria->offset = 1; //When the two are combined, it means limit 10 offset 1, or it represents. limit 1,10
$criteria->order = 'xxx DESC,XXX ASC' ;//Sort conditions
$criteria->group = 'group criteria';
$criteria->having = 'having criteria';
$criteria->distinct = FALSE; // Is the query unique
Multiple table query
$criteria=new CDbCriteria;
$criteria->alias = 'Invoice';
$criteria->join='LEFT JOIN Client ON Client.id=Invoice.clientId';
$criteria->condition='Client.businessId='. Yii::app()->userInfo->business;