Try this
SQL. It shows the date a student starts and ends in a course in addition to a last access date. This query is setup to only return active students. -Ben
---
select
c.id courseid,
c.fullname course,
u.id userid,
concat(u.lastname, ', ', u.firstname) student,
DATE_FORMAT(from_unixtime(ue.timestart),'%Y-%m-%d') start_date,
DATE_FORMAT(from_unixtime(ue.timeend),'%Y-%m-%d') end_date,
(SELECT DATE_FORMAT(FROM_UNIXTIME(timeaccess),'%Y-%m-%d') FROM prefix_user_lastaccess WHERE userid=u.id AND courseid=c.id) AS CourseLastAccess
FROM prefix_course AS c
JOIN prefix_enrol AS en ON en.courseid = c.id
JOIN prefix_user_enrolments AS ue ON ue.enrolid = en.id
JOIN prefix_user AS u ON ue.userid = u.id
JOIN prefix_context AS ct ON c.id = ct.instanceid
JOIN prefix_role_assignments AS ra ON ra.contextid = ct.id
JOIN prefix_role r on ra.roleid = r.id
WHERE r.name = 'student'
AND ra.userid = u.id
AND ra.userid = ue.userid
and unix_timestamp() between ue.timestart and ue.timeend
#use this for a course specific global report
#and c.id = '%%COURSEID%%'