2
我需要連接兩個表以獲取具有多個條件的leftjoin數據,但是
我收到此錯誤。 關於on子句沒有足夠的參數我正在使用laravel5.2。如何使用帶有leftjoin多重條件的原始查詢。如何在lajvel5中使用原始查詢中的leftjoin中的多個條件
$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"))
我已經解決了我的問題,一個大量的分析後,我沒有得到任何形式的原始查詢溶液中加入條款,然後我使用子查詢和解決我的問題。 –