使用selectRaw和time diff在查询中出现语法错误

时间:2015-11-19 10:55:23

标签: sql laravel

请告知如何更正此查询

        $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)

1 个答案:

答案 0 :(得分:1)

您有一个sintax错误可能是因为您不必在SELECT函数中编写selectRaw关键字(在这种情况下,查询构建器会添加关键字):

->selectRaw("time(sum(TIMEDIFF( 'shift_end_time', 'shift_start_time' )))")
相关问题