Php 将带BETWEEN的mysql查询转换为laravel查询

Php 将带BETWEEN的mysql查询转换为laravel查询,php,mysql,laravel,Php,Mysql,Laravel,请建议如何继续以下针对laravel的mysql查询 sql 从班次中选择* 其中,时间表id=11,且在轮班开始时间和轮班结束时间之间为(“14:00”) 或在轮班开始时间和轮班结束时间之间的“15:00” 或“14:00”>=班次\开始时间\和“15:00”时间\工作表\ id) ->其中('user\u id','=',$user\u id->user\u id) ->其中('role_id','=',1) ->其中(输入::get('shift\u start\u time')、数组('

请建议如何继续以下针对laravel的mysql查询

sql

从班次中选择*
其中,时间表id=11,且在轮班开始时间和轮班结束时间之间为(“14:00”)
或在轮班开始时间和轮班结束时间之间的“15:00”
或“14:00”>=班次\开始时间\和“15:00”时间\工作表\ id)
->其中('user\u id','=',$user\u id->user\u id)
->其中('role_id','=',1)
->其中(输入::get('shift\u start\u time')、数组('shift\u start\u time'、'shift\u end\u time'))
->其中(输入::get('shift\u end\u time')、数组('shift\u start\u time'、'shift\u end\u time'))
->其中(输入::get('shift\u end\u time'),'>=','shift\u start\u time')
->其中(输入::get('shift\u end\u time'),'time\u sheet\u id和user\u id=$user\u id->user\u id')
->whereRaw('Input::get('shift_start_time')在shift_start_time和shift_end_time之间;或
输入::在轮班开始时间和轮班结束时间之间获取(“轮班结束时间”),或

输入::get('shift\u start\u time')>=shift\u start\u time和输入::get('shift\u end\u time'))我的答案不符合您的要求,这就是我删除它的原因。现在我看到您想要在两个不同的列之间查询时间。据我所知,这不能用
whereBetween
来完成。您应该使用
whereRaw
并复制原始查询。shift\u start\u time的数据类型是什么?是字符串、日期还是日期时间?哪一个?@Tim:你能检查一下更新部分的查询吗?我用whereRaw试过了。请advice@ogres数据类型是time我的答案不能按您想要的方式工作,这就是我删除它的原因。现在我看到您想要查询两个不同列之间的时间。据我所知,这不能用
wherebeen
来完成。您应该使用
whe重新读取
并复制原始查询。shift\u start\u time的数据类型是什么?是字符串、日期还是日期时间?哪一种?@Tim:请检查更新部分查询。我尝试了WHERRAW。请advice@ogres数据类型是时间
SELECT * FROM shifts
WHERE  time_sheet_id = 11 AND ( "14:00" BETWEEN shift_start_time AND shift_end_time
   OR "15:00" BETWEEN shift_start_time AND shift_end_time
   OR "14:00" >= shift_start_time AND "15:00" <= shift_end_time )
 $shiftData = Shifts::where('time_sheet_id', '=', $getTimesheet1->time_sheet_id)
            ->where('user_id', '=', $user_id->user_id)
            ->where('role_id', '=', 1)
            ->whereBetween(Input::get('shift_start_time'), array('shift_start_time ' , 'shift_end_time '))
            ->whereBetween(Input::get('shift_end_time') , array('shift_start_time ' , 'shift_end_time '))
            ->where( Input::get('shift_end_time'), '>=', 'shift_start_time ')
            ->where(Input::get('shift_end_time'), '<=',  'shift_end_time ')
            ->get();
SQLSTATE[42S22]: Column not found: 1054 Unknown column '18:00:00' in 'where clause' (SQL: select * from `shifts` where `time_sheet_id` = 12 and `user_id` = 2 and `role_id` = 1 and `18:00:00` between shift_start_time and shift_end_time and `20:00:00` between shift_start_time and shift_end_time and `20:00:00` >= shift_start_time and `20:00:00` <= shift_end_time )
$shiftData=   DB::table(DB::raw('shifts'))
        ->whereRaw('time_sheet_id = $getTimesheet1->time_sheet_id AND user_id = $user_id->user_id')
        ->whereRaw('Input::get('shift_start_time') BETWEEN shift_start_time AND shift_end_time OR
Input::get('shift_end_time') BETWEEN shift_start_time AND shift_end_time OR
Input::get('shift_start_time') >= shift_start_time AND Input::get('shift_end_time') <= shift_end_time')
        ->count();