mysql - Moodle SQL query to retrieve all users enrolled to a course in the past 90 days -
hey guys can me, need sql query give me users enrolled course in last 90 days not suspended.
i've done searching , found this:
select distinct u.id userid, c.id courseid mdl_user u join mdl_user_enrolments ue on ue.userid = u.id join mdl_enrol e on e.id = ue.enrolid join mdl_role_assignments ra on ra.userid = u.id join mdl_context ct on ct.id = ra.contextid , ct.contextlevel = 50 join mdl_course c on c.id = ct.instanceid , e.courseid = c.id join mdl_role r on r.id = ra.roleid , r.shortname = 'student' e.status = 0 , u.suspended = 0 , u.deleted = 0 , (ue.timeend = 0 or ue.timeend > now()) , ue.status = 0
i can return results specific course adding and courseid = 11
end of query, i'm still struggling date range.
i've tried using:
and ue.timecreated between now() - interval 90 day , now()
but returning no results tried add 2000 day range , returns nothing
this current modified query:
select distinct u.id userid, c.id courseid, date_format(ue.timecreated, '%m/%d/%y') mdl_user u join mdl_user_enrolments ue on ue.userid = u.id join mdl_enrol e on e.id = ue.enrolid join mdl_role_assignments ra on ra.userid = u.id join mdl_context ct on ct.id = ra.contextid , ct.contextlevel =50 join mdl_course c on c.id = ct.instanceid , e.courseid = c.id join mdl_role r on r.id = ra.roleid , r.shortname = 'student' e.status =0 , u.suspended =0 , u.deleted =0 , ( ue.timeend =0 or ue.timeend > now() ) , ue.status =0 , ue.timecreated between now() - interval 1200 day , now() , courseid = 11
and return nothing, remove second-last line contains date range receive results inside course id 11.
basically need:
a list of users enrolled in specific course in last 90 days not suspended or deleted.
results like:
course id: 20 user id: 200, 533, 221, 22, 356
cheers,
dan
the solution here:
select distinct u.id userid, c.id courseid, date_format(from_unixtime(ue.timecreated),'%m/%d/%y') timecreated mdl_user u join mdl_user_enrolments ue on ue.userid = u.id join mdl_enrol e on e.id = ue.enrolid join mdl_role_assignments ra on ra.userid = u.id join mdl_context ct on ct.id = ra.contextid , ct.contextlevel =50 join mdl_course c on c.id = ct.instanceid , e.courseid = c.id join mdl_role r on r.id = ra.roleid , r.shortname = 'student' e.status =0 , u.suspended =0 , u.deleted =0 , ( ue.timeend =0 or ue.timeend > now( ) ) , ue.status =0 , courseid =11 , from_unixtime(ue.timecreated) between curdate() - interval 90 day , curdate()
Comments
Post a Comment