如何在不使用yii\db\Expression
和原始sql的情况下使用子表达式构建查询。例如:
SELECT * FROM user WHERE archived = 3 AND ((group = 2 AND status = 3) OR (group = 3 AND status = 2));
答案 0 :(得分:1)
您可以使用数组表达式建立这样的条件:
$users = (new Query())
->from('user')
->where(['archived' => 3])
->andWhere([
'or',
[
'group' => 2,
'status' => 3,
],
[
'group' => 3,
'status' => 2,
],
])
->all();