我的查询如下。
$subQuery = (new Query())->select('is_approved')->from('user_requests')->where(['user_ref_id' => yii::$app->user->id])->andWhere(['AND','project_ref_id = p.project_id']);
这是我试图在select语句中调用的子查询,如下所示
$Query = (new Query())->select(['project_id','IF(p.project_type_ref_id = 2, '.$subQuery.', "" ) AS project_request_id'])
->from('projects AS p');
如果我尝试执行查询,我在添加$ subQuery
的行中出现以下错误PHP Recoverable Error – yii\base\ErrorException
Object of class yii\db\Query could not be converted to string
如何在select语句中添加子查询。请帮忙。在此先感谢!!
答案 0 :(得分:0)
由于您希望将第一个查询用作纯字符串添加
->createCommand()->rawSql;
到它。这会从Query对象生成SQL语句。