I have a MariaDB query that runs fine in the database query.
SELECT student_id, last_name, first_name , Count(id) as courses FROM registrations
WHERE student_id NOT IN (SELECT student_id FROM exclude_from_tracking_list)
GROUP BY student_id
HAVING COUNT(*) > 3
ORDER BY last_name
But can not get it to run in laravel 8.
DB::statement('with query')
DB::table('registrations')
->selectRaw('student_id, last_name, first_name , Count(id) as courses')
->where(DB::raw('student_id NOT IN (SELECT student_id FROM exclude_from_tracking_list'))
->groupBy('student_id')
->havingRaw('COUNT(*) > 3')
->orderBy('last_name')
->get();
What am I missing. I've search and tried many other options.
But I keep getting this error
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'is null group by
student_id
having COUNT() > 3 order bylast_name
asc' at line 1 (SQL: select student_id, last_name, first_name , Count(id) as courses fromregistrations
where student_id NOT IN (SELECT student_id FROM exclude_from_tracking_list is null group bystudent_id
having COUNT() > 3 order bylast_name
asc)
Any help would be appreciated.