请告知如何更正此查询
$no_of_hours = DB::Table('shifts')
->where('time_sheet_id','=', $timesheet_id->id)
->selectRaw("SELECT time(sum(TIMEDIFF( 'shift_end_time', 'shift_start_time' )))")
->get();
return $no_of_hours;
我得到以下错误
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SELECT time(sum(TIMEDIFF( 'shift_end_time', 'shift_start_time' ))) from `shifts`' at line 1 (SQL: select SELECT time(sum(TIMEDIFF( 'shift_end_time', 'shift_start_time' ))) from `shifts` where `time_sheet_id` = 35)
答案 0 :(得分:1)
您有一个sintax错误可能是因为您不必在SELECT
函数中编写selectRaw
关键字(在这种情况下,查询构建器会添加关键字):
->selectRaw("time(sum(TIMEDIFF( 'shift_end_time', 'shift_start_time' )))")