代码之家  ›  专栏  ›  技术社区  ›  Freddy Abagnale

Laravel查询生成器中的多列比较

  •  0
  • Freddy Abagnale  · 技术社区  · 7 年前

    SELECT name
         , firstname 
    FROM emp
    WHERE name+' '+firstname LIKE '%test%'
    

    在查询生成器中?我怎么会有同样的结果?

    3 回复  |  直到 7 年前
        1
  •  1
  •   Mr. Pyramid    7 年前

    你可以在 whereRaw() 这样地

    DB::table('emp')->whereRaw("name+' '+firstname LIKE '%test%'")->select('name', 'firstname')->get();

        2
  •  1
  •   Siva Ganesh    7 年前
     $result = DB::table('emp')->select('name', 'firstname')->where(DB::raw("CONCAT('name', ' ', 'firstname')"), 'LIKE', '%'. 'test' .'%')->get();
    
        3
  •  0
  •   Meera Tank    7 年前

    尝试使用 CONCAT 对于多列

    DB::table('emp')->Where(DB::raw("CONCAT(`name`, ' ', `firstname`)"), 'LIKE', "%test%")->select('name', 'firstname')->get();