Thinkphp5.1 SQL或查询

1,或的一种情况

    $map1 = [
        ['A.user_group_id', '=', '1'],
    ];
    
     $map2 = [
        ['A.user_group_id', '=', '2'],
    ];
Db::table('user')->alias('A')->leftJoin(member B', 'A.id = B.user_id')
        ->field('A.id,A.username')
        ->whereOr([$map1, $map2 ])
        ->where(['A.status'=>'verified'])
       ->order('A.id', 'desc')->select();

2,或的第二情况

   $wheres[] = ['A.cerate_time|A.visiting_time','between',[$start_time,$end_time]];
    $total = Db::table('invited')->alias('A')->field('A.id')->where($wheres)->count();
    $listorder = [];
    $listorder['A.visiting_time'] = 'asc';
    $cusarr = Db::table('invited')->alias('A')
        ->field('A.*')
        ->where($wheres)->order($listorder)
        ->select();

你可能感兴趣的:(Thinkphp)