我要檢查的總和值和laravel 4.2查詢的WHERE條件計數值怎麼樣查詢中使用與計數值在MySQL中laravel 4.2
下面的代碼,我有
$aColumns = array('driver_details.DriverId', DB::raw('CONCAT(driver_details.Firstname, " ", driver_details.Lastname, "/", driver_details.TaxiPlateNo) AS TaxiDriver'), DB::raw('count(taxi_trip.AutoId) AS TotalTrip'), DB::raw('sum(taxi_trip.TripDistance) AS TotalTripDistance'), DB::raw('sum(taxi_trip.TotalFare) AS TotalTripFare'));
$aColumnsSearch = array('driver_details.DriverId', 'driver_details.Firstname', 'driver_details.Lastname','driver_details.TaxiPlateNo',
DB::raw('count(taxi_trip.AutoId)'));
$Search='';
if(Input::get('Search')!='')
$Search = Input::get('Search');
$DriverId='';
if(Input::get('DriverId')!='')
$DriverId = Input::get('DriverId');
$IsCancel='';
if(Input::get('IsCancel')!='')
$IsCancel = Input::get('IsCancel');
$FromDate='';
if(Input::get('FromDate')!='')
$FromDate = Input::get('FromDate');
$ToDate='';
if(Input::get('ToDate')!='')
$ToDate = Input::get('ToDate');
$tempqry = DB::connection()->table('driver_details')
->select($aColumns)
->leftJoin('taxi_trip', function($join)
{
$join->on('taxi_trip.DriverId', '=', 'driver_details.DriverId');
$join->on('taxi_trip.PickupLAT', '!=', DB::raw(0));
$join->on('taxi_trip.DropLAT', '!=', DB::raw(0));
$join->on('taxi_trip.TotalFare', '!=', DB::raw(0));
})
->where(function($query) use ($FromDate) {
if($FromDate!='')
{
$query->where(DB::raw("date_format(taxi_trip.RequestDate,'%Y-%m-%d')"), '>=', date("Y-m-d",strtotime($FromDate)));
}
})
->where(function($query) use ($ToDate) {
if($ToDate!='')
{
$query->where(DB::raw("date_format(taxi_trip.RequestDate,'%Y-%m-%d')"), '<=', date("Y-m-d",strtotime($ToDate)));
}
})
->where(function($query) use ($Search, $aColumnsSearch)
{
for ($i=0 ; $i<count($aColumnsSearch) ; $i++)
{
//$query->orWhere($aColumnsSearch[$i].' LIKE %'.$Search.'%');
$query->orWhere($aColumnsSearch[$i],'LIKE', '%'.$Search.'%');
}
})
->where(function($query) use ($DriverId) {
if($DriverId!='')
{
$query->where('taxi_trip.DriverId', '=', $DriverId);
}
})
->groupby('driver_details.DriverId');
$temp = $tempqry;
$tempqry = $temp->get();
return $tempqry;
我希望使用從查詢獲得的count()和sum()值與我正在給的搜索值
您嘗試迄今爲止達到此目的? –