2017-04-22 160 views
0

我試圖讓從幾小時此查詢,但我不能讓這個查詢在laravel語法Laravel 5.1嵌套複雜的查詢

\DB::select(\DB::raw(
" 
SELECT * FROM products AS P WHERE (`d` = $d) 
      AND (`mis` BETWEEN $min_c AND $max_c) 
      AND (`e` BETWEEN $e_min AND $e_max) 
      AND p1 IN 
          (
          SELECT p1 
          FROM autos AS A 
          WHERE (`ma` = $strma) 
          AND (`d` = $d) 
          AND (`mis` BETWEEN $min_c AND $max_c) 
          AND (`e` BETWEEN $e_min AND $e_max) 
          AND (`p1` = P.p1) 
          AND (`p2` = P.p2) 
          ) 
      AND p2 IN 
          (
          SELECT p2 
          FROM autos AS A 
          WHERE (`ma` = $strma) 
          AND (`d` = $d) 
          AND (`mis` BETWEEN $min_c AND $max_c) 
          AND (`e` BETWEEN $e_min AND $e_max) 
          AND (`p1` = P.p1) 
          AND (`p2` = P.p2) 
          ) 
"    
)); 

我想我必須使用2種功能,如

->whereIn(array('p1','p2'), 
function($query){ 

... 
} 
function($query2){ 
... 
} 
) 

但它沒有工作 以什麼方式可以問這個數據庫在laravel語法?

+1

會發生什麼?你的問題在Mysql或Laravel上?您是否直接在MySql更直接的界面上嘗試查詢?這是非常不清楚你的問題是什麼! – sergiol

回答

0

我解決了它在2中的功能。

->whereIn('p1',function($query) use (... 
->whereIn('p2',function($query2) use (...