大家好我有以下查询要执行。我正在执行它作为字符串sql但是有任何方法我可以将其转换为条件格式或Yii中的正确命令格式...
$sql="select * from costing inner join
(select * from storage inner join costing_user_binding psb on user.user=psb.fk_user_id where user.fk_users_id IN $parents_id)
view on costing.costing_id=view.fk_costing_id where costing.fk_user_types_id = {$session['role_level']} and costing.fk_product_types_id=2";
$result = Yii::app()->db->createCommand($sql)->queryAll();
答案 0 :(得分:2)
你可以试试这个......
$subQuery=$model->getCommandBuilder()->createFindCommand($model->getTableSchema(),$criteria)->getText();
$mainCriteria=new CDbCriteria();
$mainCriteria->condition=' (col1,col2,col3) in ('.$subQuery.') ';
$mainCriteria->order = 'col1,col2,col3';