2017-07-21 10 views
2

左結合で複数条件のデータをフェッチするには2つのテーブルを結合する必要がありますが、
このエラーが発生します。 on節の引数が不十分です私はlaravel5.2を使用しています。 leftjoinの複数の条件で生のクエリを使用する方法。leftjoinで複数条件を使用してlaravel5で未処理クエリを使用する方法

$activityDetail = DB::table('table1 as UA') 
     ->selectRaw('SUM(UA.total_calory) as total_calory, 
      SUM(UA.flight_descend) as flight_descend,date('.$tz_start_date.') as start_date') 
     ->leftjoin('table2 as LC',function($join) use($tz_lccreated_date,$dateRange){ 
       $join->on('LC.user_id_fk','=','UA.user_id_fk'); 
       $join->on('LC.is_active','=',DB::raw('1')); 
       $join->on(' date('.DB::raw($tz_lccreated_date).') '.DB::raw($dateRange)); 
      }) 
      ->whereRaw(' date('.$tz_start_date.') '.$dateRange) 
      ->where('UA.user_id_fk','=',base64_decode($params['uid'])) 
      ->groupBy(DB::raw('date('.$tz_start_date.')')) 
      ->get(); 

Raw query is 

select SUM(UA.total_calory) as total_calory, 
SUM(UA.flight_descend) as flight_descend, 
date(CONVERT_TZ(UA.start_date,"+00:00","+05:30")) as start_date 
from `table1` as `UA` 
left join `table2` as `LC` 
on `LC`.`user_id_fk` = `UA`.`user_id_fk` and `LC`.`is_active` = 1 
and `date(CONVERT_TZ(LC`.`created_date,"+00:00","+05:30"))` = `current_date` 
where date(CONVERT_TZ(UA.start_date,"+00:00","+05:30")) = current_date 
and `UA`.`user_id_fk` = 411 
group by date(CONVERT_TZ(UA.start_date,"+00:00","+05:30")) 
+0

私は分析の多くの後、私は中に、私はサブクエリを使用しています句に参加し、私の問題を解決し、生のクエリのソリューションのいずれかの種類を取得していないです、私の問題を解決してきました。 –

答えて

0
I have resolved my problem, after a lots of analysis, i am not getting any kind of solution of raw query in join clause then i am using subquery and resolve my problem. 

$mannualLoggedQuery = 'IFNULL((select sum(calory) as cal from table2 as LC where LC.user_id_fk = "'.base64_decode($params['uid']).'" and date('.$tz_lccreated_date.')'.$dateRange.'),0)'; 


$activityDetail = DB::table('table1 as UA')->selectRaw('SUM(UA.total_calory) + '.$mannualLoggedQuery.' as total_calory, 

            date('.$tz_start_date.') as start_date') 
            ->where('UA.user_id_fk','=',base64_decode($params['uid'])) 
            ->whereRaw('date('.$tz_start_date.') '.$dateRange) 
            ->groupBy(DB::raw('date('.$tz_start_date.')')) 
            ->get(); 
+0

私の問題を解決する.... –

関連する問題