Yii2 Query Where

https://blog.csdn.net/hzqghost/article/details/44117081

where('status=1')->
where('status=:status', [':status' => $status])->
where([
    'status' => 10,
    'type' => null,
    'id' => [4, 8, 15],
])->
-------
$userQuery = (new Query())->select('id')->from('user');
// ...WHERE `id` IN (SELECT `id` FROM `user`)
$query->...->where(['id' => $userQuery])->...
--------
['and', 'id=1', 'id=2'] //id=1 AND id=2
['and', 'type=1', ['or', 'id=1', 'id=2']] //type=1 AND (id=1 OR id=2)
['between', 'id', 1, 10] //id BETWEEN 1 AND 10
['not between', 'id', 1, 10] //not id BETWEEN 1 AND 10
['in', 'id', [1, 2, 3]] //id IN (1, 2, 3)
['not in', 'id', [1, 2, 3]] //not id IN (1, 2, 3)
['like', 'name', 'tester'] //name LIKE '%tester%'
['like', 'name', ['test', 'sample']] //name LIKE '%test%' AND name LIKE '%sample%'
['not like', 'name', ['or', 'test', 'sample']] //not name LIKE '%test%' OR not name LIKE '%sample%'
['exists','id', $userQuery] //EXISTS (sub-query) | not exists
['>', 'age', 10] //age>10

发表评论

电子邮件地址不会被公开。 必填项已用*标注