欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

YII2中andWhere多个or查询

程序员文章站 2024-02-01 17:48:04
使用多个or的复杂查询:AND (name=‘张三’) OR (name=‘李四’) OR (name=‘王五’) // AND (`name`='张三') OR (`name`='李四') OR (`name`='王五') $query->andWhere(['or', ['name' => '张 ......

 

 

使用多个or的复杂查询:
and (name=‘张三’) or (name=‘李四’) or (name=‘王五’)

// and (`name`='张三') or (`name`='李四') or (`name`='王五')
$query->andwhere(['or',
    ['name' => '张三'],
    ['name' => '李四'],
    ['name' => '王五']
]);

and (((name=‘张三’) and (phone=‘15200000000’)) or ((name=‘李四’) and (phone=‘15300000000’)))

// and (((`name`='张三') and (`phone`='15200000000')) or ((`name`='李四') and (`phone`='15300000000')))
$query->andwhere(['or',
    ['and',
        ['name' => '张三'],
        ['phone' => '15200000000']
    ],
    ['and',
        ['name' => '李四'],
        ['phone' => '15300000000']
    ]
]);