Moodle MySQL Queries
Here are some Moodle MySQL Queries that are useful for generating activity statistics:
From http://blog.weber.k12.ut.us/jreeve/some-simple-mysql-queries-for-moodle/
Find the most popular activities:
SELECT
COUNTCOUNT(l.id) hits, moduleFROMmoduleFROM mdl_log lWHERElWHERE module != ‘login’'login' AND module != ‘course’'course' AND module != ‘role’
'role'GROUP BY moduleORDERmoduleORDER BY hits DESC
Find the most active users over the past 7 days
(change the “604800″ to the number of the appropriate number of seconds if you want to adjust this interval):
SELECT
COUNTCOUNT(l.id) hits, l.userid, u.username, u.firstname, u.lastnameFROMlastnameFROM mdl_log l INNER JOIN mdl_user u ON l.userid = u.idWHEREidWHERE l.time > UNIX_TIMESTAMP(NOWNOW()) –- 604800GROUP604800GROUP BY l.useridORDERuseridORDER BY hits DESC
Find the most active courses:
(You may need to change the second line to FROM mdl_log l INNER JOIN mdl_course c ON l.course = c.id AND c.id != ‘1′ to omit home page hits)
SELECT
COUNTCOUNT(l.id) hits, l.course courseId, c.fullname coursenameFROMcoursenameFROM mdl_log l INNER JOIN mdl_course c ON l.course = c.idGROUPidGROUP BY courseIdORDERcourseIdORDER BY hits DESC
Some SSCcustom written ones:
Find the number of resources per course:
SELECT
COUNTCOUNT(l.id) count, l.course, c.fullname coursenameFROMcoursenameFROM mdl_resource l INNER JOIN mdl_course c on l.course = c.idGROUPidGROUP BY courseORDERcourseORDER BY count DESC