Ad-hoc database queries
Reports ::: report_customsql
Maintained by
Tim Hunt,
Mahmoud Kassaei,
Anupama Sarjoshi
This report plugin allows Administrators to set up arbitrary database queries
to act as ad-hoc reports. Reports can be of two types, either run on demand,
or scheduled to run automatically. Other users with the right capability can
go in and see a list of queries that they have access to. Results can be viewed
on-screen or downloaded as CSV.
Latest release:
3836 sites
1k downloads
148 fans
Current versions available: 10
This report, created by The Open University, lets Administrators set up arbitrary SQL select queries that anyone with the appropriate permissions can then run. Reports can be set to be runnable on-demand, or automatically run weekly or monthly.
The results are displayed as a fairly plain HTML table, and can also be downloaded as CSV.
The idea is that this lets you quicly set up ad-hoc reports, without having to create a whole new admin report plugin.
Contributors
Tim Hunt (Lead maintainer)
Mahmoud Kassaei: Developer
Anupama Sarjoshi: Tester & Developer
Please login to view contributors details and/or to contact them
SELECT Company, StudentID, Student, Course, GROUP_CONCAT(Item)
FROM (
SELECT Institution AS 'Company', u.id AS StudentID, CONCAT(u.lastname, ', ', u.firstname) AS 'Student', c.fullname AS Course, gi.itemname AS 'Item', gg.itemid AS ItemsCompleted
FROM prefix_user AS u
JOIN prefix_groups_members AS gm ON gm.userid = u.id
JOIN prefix_groups AS g ON g.id = gm.groupid
JOIN prefix_course AS c ON c.id = g.courseid
JOIN prefix_grade_items AS gi ON gi.courseid = g.courseid
LEFT JOIN prefix_grade_grades As gg ON gi.id = gg.itemid
WHERE u.institution != '' AND NOT u.deleted AND gi.itemmodule = 'assign'
AND gg.itemid IS NULL
ORDER BY CONCAT(Company, Student, Course), gi.sortorder) AS tmp
GROUP BY CONCAT(Company, Student, Course)
SELECT COUNT(l.id) hits, concat('',c.fullname,'') AS Course
,(SELECT CONCAT(u.firstname,' ', u.lastname) AS Teacher
FROM prefix_role_assignments AS ra
JOIN prefix_context AS ctx ON ra.contextid = ctx.id
JOIN prefix_user AS u ON u.id = ra.userid
WHERE ra.roleid = 3 AND ctx.instanceid = c.id LIMIT 1) AS Teacher
,CASE
WHEN c.fullname LIKE '%-13%' THEN '2013'
WHEN c.fullname LIKE '%-14%' THEN '2014'
WHEN c.fullname LIKE '%-15%' THEN '2015'
END AS YEAR
,(SELECT COUNT(*) FROM prefix_course_modules cm WHERE cm.course = l.course) Modules
,(SELECT COUNT( ra.userid ) AS Users FROM prefix_role_assignments AS ra
JOIN prefix_context AS ctx ON ra.contextid = ctx.id
WHERE ra.roleid = 5 AND ctx.instanceid = c.id) AS Students
FROM prefix_log l
INNER JOIN prefix_course c ON l.course = c.id
GROUP BY c.id
HAVING Modules > 2
ORDER BY YEAR DESC, hits DESC
However, I am having problems entering a date as parameter.
This works:
SELECT
subject, firstname, lastname, email, FROM_UNIXTIME(created)
FROM
{forum_posts}
INNER JOIN
{user} ON {forum_posts}.userid = {user}.id
WHERE
parent > 0
AND FROM_UNIXTIME(created) BETWEEN '2015/04/27' AND '2015/05/03'
Whereas this doesn't (although it correctly prompts for start and finish dates):
SELECT
subject, firstname, lastname, email, FROM_UNIXTIME(created)
FROM
{forum_posts}
INNER JOIN
{user} ON {forum_posts}.userid = {user}.id
WHERE
parent > 0
AND FROM_UNIXTIME(created) BETWEEN :start_date AND :end_date
Any thoughts why?
Thank you for your time.
Craig
as it is pointing to 2.2 at the moment with lots of references to Moodle 1.9 which makes it look rather
out of date. If you just take out the version bit (the 22) it should automatically redirect to the latest version
i.e. https://docs.moodle.org/en/Custom_SQL_queries_report
We are using this tool to collect daily attendance to be imported to our SIS. Ideally I would like to have the csv file automatically dropped to ftp. The few extra steps we take daily to download the report and place it in a file is mildly annoying. BUT that being said is still 1000 times better than collecting and posting attendance by hand. Not complaining, I am very grateful for this tool. Just a suggestion regarding the ftp drop.
Hi,
I'm wondering if anyone has written AN SQL query for generating an attendance report for all students for all courses?
Love the power of this!
When I schedule a run of a sql query it never runs. The command crontab -l shows nothing scheduled and I see no cron.php in the report/customsql directory
Is there something I need to do to have a query run at a specific time?
Thanks
Tim