The query below is the one that I use to show me all students and their final grades. I actually have this in my Configurable Reports. I will give you the CR (prefix_) form of this query. You might need to add one more WHERE clause to filter on gg.finalgrade. Notice that I am also filtering on final grade IS NOT NULL. Maybe you would want "IS NULL" to find students who do not yet have a final grade. In my case, if the student had received a grade on any item in the grade book, they will have a final grade. If you are using Activity Completion, you would need to add something in the query to filter on it.
Well, this is a start. I began this by looking at some of the contributed queries first, and then modified it. I cannot guarantee that it is 100% accurate, but it works well for my needs.
SELECT DISTINCT c.shortname AS CourseName,
u.firstname AS FirstName,
u.lastname AS LastName,
u.email AS Email,
gg.finalgrade AS FinalGrade,
c.idnumber AS CourseIDNum,
gi.courseid AS CourseNumber,
gg.userid AS StudentID,
3 AS moodleversion
FROM prefix_grade_items gi
JOIN prefix_grade_grades gg ON gi.id = gg.itemid
JOIN prefix_course c ON c.id = gi.courseid
JOIN prefix_user u ON u.id = gg.userid
JOIN prefix_context ct ON ct.instanceid = gi.courseid
JOIN prefix_role_assignments ra ON ra.userid = gg.userid
JOIN prefix_user_enrolments ue ON u.id = ue.userid
JOIN prefix_enrol e ON e.courseid = gi.courseid
WHERE gi.itemtype = "course"
AND gg.finalgrade IS NOT NULL
AND u.suspended = 0
AND u.deleted = 0
AND ct.contextlevel = 50
AND ra.roleid = 5
AND ct.id = ra.contextid
AND ue.status = 0
AND e.status = 0
AND e.id = ue.enrolid
ORDER BY c.idnumber DESC,
u.lastname,
u.firstname