thinkphp6 where优先级查询

$map[] = ['id','>',0];
$map[] = ['sex',1];
$map[] = ['color','blue'];

Db::name('student')
    ->where($map)
    ->where(['name','like','%efs%'])
    ->select();

SELECT * FROM `student` WHERE `id` > 0 AND `sex` = 1 AND `color` = 'blue' AND 'name' LIKE '%efs%';

Db::name('student')
    ->where([$map])
    ->where(['name','like','%efs%'])
    ->select();

SELECT * FROM `student` WHERE ( `id` > 0 AND `sex` = 1 AND `color` = 'blue' ) AND 'name' LIKE '%efs%';

一般情况下,where()连缀生成的sql语句是并列AND条件的,当出现优先时,如上所示,如要优先查询$map中的条件再查询’name’条件,只需在where()中加入'[]’即可


已发布

分类

作者:

标签

评论

发表回复

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