Help required in Query for Custom Report

Help required in Query for Custom Report

by Aditya Dubay -
Number of replies: 6

Hi,

I am using Moodle 3.6

In custom report I can get logged in users by this query:

SELECT id, username, firstname, lastname,FROM_UNIXTIME( lastaccess ) AS lastaccess
FROM prefix_user
WHERE DATEDIFF( NOW(),FROM_UNIXTIME( lastaccess ) ) < 1100

 Now, I need to add user's course and email address in this query.

How can I add ?

 

Please help...

Average of ratings: -
In reply to Aditya Dubay

Re: Help required in Query for Custom Report

by Aditya Dubay -

Do help please

In reply to Aditya Dubay

Re: Help required in Query for Custom Report

by Rick Jerz -
Picture of Particularly helpful Moodlers Picture of Testers
In reply to Rick Jerz

Re: Help required in Query for Custom Report

by Aditya Dubay -

Hi Rick,

Thanks for reply.

Above query is from the same link. I need to add course in addition.

In reply to Aditya Dubay

Re: Help required in Query for Custom Report

by Rick Jerz -
Picture of Particularly helpful Moodlers Picture of Testers

I don't have time right not to write the full query, but you need to combine your above query with the contributed report query.

This one give you students in all courses:

SELECT c.id, c.fullname, u.firstname, u.lastname, u.deleted

FROM mdl_course AS c

JOIN mdl_context AS ctx ON c.id = ctx.instanceid

JOIN mdl_role_assignments AS ra ON ra.contextid = ctx.id

JOIN mdl_user AS u ON u.id = ra.userid

WHERE ra.roleid =5

AND ctx.instanceid = c.id

In reply to Rick Jerz

Re: Help required in Query for Custom Report

by Aditya Dubay -

Thanks for reply Rick...

Your query says "No explicit prefix"

In reply to Aditya Dubay

Re: Help required in Query for Custom Report

by Rick Jerz -
Picture of Particularly helpful Moodlers Picture of Testers

My guess is that you might have to change my table prefix, "mdl_" to whatever your Moodle is using.  This prefix gets established when one installs Moodle.