我有一些查询,我只知道如何在mysql(phpmyadmin)上查询
如果使用DB::select
我们不能使用分页,我会得到信息,因此我们需要将DB::table(some query)
更改为使用分页。
但是问题是我对如何将查询转换为DB::table(some query)
这是我的代码
$daily = DB::select("
SELECT
employees.employee_name,
COUNT(DISTINCT DATE(attendance.attendance_datetime)) as jumlah,
locations.location_name,
TIME(MIN(attendance.attendance_datetime)) as check_in,
CASE
WHEN ISNULL(TIME(MIN(attendance.attendance_datetime))) THEN attendance_absence.remarks
WHEN TIME(MIN(attendance.attendance_datetime)) > '08:05:00' THEN (SELECT TIMEDIFF('08:05:00', MIN(TIME(attendance_datetime))))
WHEN TIME(MIN(attendance.attendance_datetime)) <= '08:05:00' THEN 'Good'
ELSE 'No Record'
END as detail_telat,
attendance_absence.remarks as remarks
FROM
employees
LEFT JOIN attendance ON employees.employee_name = attendance.attendance_name AND DATE(attendance.attendance_datetime) = '$date'
LEFT JOIN locations ON employees.location_id = locations.id
LEFT JOIN attendance_absence ON attendance_absence.employee_name = employees.employee_name AND attendance_absence.absences_date = '$date'
WHERE locations.location_name LIKE '%'
GROUP BY employees.employee_name
ORDER BY employees.employee_name
")->paginate(3);
请帮助我将查询转换为雄辩的查询或查询生成器,或任何建议吗?
答案 0 :(得分:2)
当前,使用Laravel无法有效执行使用groupBy语句的分页操作。如果需要使用具有分页结果集的groupBy,建议您查询数据库并手动创建分页器。