zoukankan      html  css  js  c++  java
  • 【Laravel】DB查询 where 例子记录

    在数据查询时候,多条件查询,使用场景

    //单个值
    $data_where['id'] = 1
    
    // in 条件 写法一
    $ids = [1,2,3,4,5];
    $data_where[] = [DB::raw("字段名 in ({$ids})"),'1'];
    //in条件写法二
    $data_where[] = ['in'=>['id'=>$ids]];
    
    $condition[] =['id','in',$ids]; // 这是错误的写法
    // IlluminateDatabaseQueryBuilder关于operators定义中,并没有in
    public $operators = [
        '=', '<', '>', '<=', '>=', '<>', '!=',
        'like', 'like binary', 'not like', 'between', 'ilike',
        '&', '|', '^', '<<', '>>',
        'rlike', 'regexp', 'not regexp',
        '~', '~*', '!~', '!~*', 'similar to',
        'not similar to', 'not ilike', '~~*', '!~~*',
    ];
    
    
    

    经测试,上述方法 in 的时候 无法使用

    后改为如下实现:

     $check = Db::table('check as c')
    ->leftJoin('report as  r','r.check_code','=','c.num')
    ->where(function ($query) use ($user_id,$user_info,$param) {
         //场景一: where 的 或条件
          $query->where(function ($query) use ($name) {
               $query->where('pt.name', '=', $name)->orWhere('p.name', '=', $name);
          });      
         //场景二: in条件
         $query->whereIn('o.scan_doctor_id', [1,2,3]);
    
    })->orderBy('c.update_time','desc')
    ->select(['r.id'])
    ->paginate(10);
    
    
  • 相关阅读:
    OpenCV 之 图像平滑
    C++11 之 nullptr
    C++11 之 scoped enum
    C++ 之 常量成员函数
    德国的挑战
    OpenCV 之 直方图处理
    OpenCV 之 霍夫变换
    排序算法之——归并排序(两种方法及其优化)
    排序算法之——快速排序(剖析)
    排序算法之——桶排序
  • 原文地址:https://www.cnblogs.com/richerdyoung/p/13836648.html
Copyright © 2011-2022 走看看