在标记为重复问题之前,请阅读它。我在这里有不同的问题。我想使用 yii2 搜索模型生成这种查询。
select * from t1 innerjoin t2 on (t1.id = t2.id) where ((t1.price >= '1000' and t1.price <= '5000') OR
( t2.price >= '1000' and t2.price <= '5000' ))
在这里加入不是问题。主要问题是 where 子句。我试过了,但没有用。
$query->andFilterWhere([
'and',
['>=', 't1.price', $this>start_price],
['<=', 't1.price', $this->end_price]
])
->orFilterWhere([
'and',
['>=', 't2.price', $this->start_price],
['<=', 't2.price', $this->end_price]
]);
最佳答案
尝试
$query->andFilterWhere([
'or',
[
'and',
['>=', 't1.price', $this>start_price],
['<=', 't1.price', $this->end_price]
],
[
'and',
['>=', 't2.price', $this->start_price],
['<=', 't2.price', $this->end_price]
]
]);
关于php - 如何在 yii2 的 AndWhere 中使用嵌套条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38586372/