1

海刚!

我非常接近于找出一份报告,我可以临时运行以查找我们所有未注册课程的用户。我确实有一份针对尚未完成课程的已注册人员的报告,但是此搜索未找到甚至未注册的给定学生。

当前代码是

SELECT u.lastname, u.firstname , u.email , c.fullname, 

DATE_FORMAT(FROM_UNIXTIME(cc.timecompleted),'%m/%d/%Y %T') AS 'Completed'

FROM 
prefix_role_assignments AS ra
JOIN prefix_context AS context ON context.id = ra.contextid 

AND
context.contextlevel = 50 JOIN prefix_course AS c ON c.id = context.instanceid

AND
 c.fullname LIKE "SAMPLE_COURSE_NAME" 
JOIN prefix_user AS u ON u.id = ra.userid 
JOIN prefix_course_completions AS cc ON cc.course = c.id 
AND cc.userid = u.id

ORDER BY
cc.timecompleted,
u.lastname,
u.firstname

有什么想法吗??

4

2 回答 2

2

这将列出所有未注册课程的用户 - 虽然可能是一个很大的列表。

替换xxx为课程 ID

SELECT u.id AS userid, u.firstname, u.lastname, u.email
FROM mdl_user u
WHERE u.deleted = 0
AND u.suspended = 0
AND NOT EXISTS (
    SELECT ue.userid
    FROM mdl_user_enrolments ue
    JOIN mdl_enrol e ON e.id = ue.enrolid AND e.courseid = xxx
    WHERE ue.userid = u.id
)
于 2021-10-13T08:13:57.310 回答
1

更新...我发现使用“mdl_”在moodle框架中不起作用,但您可以用“prefix_”替换它并且它可以工作!太感谢了!我从来没有想过这个设置。

SELECT u.id AS userid, u.firstname, u.lastname, u.email
FROM prefix_user u
WHERE u.deleted = 0
AND u.suspended = 0
and firstname not like "Guest user"

AND NOT EXISTS (
    SELECT ue.userid
    FROM prefix_user_enrolments ue
    JOIN prefix_enrol e ON e.id = ue.enrolid AND e.courseid = XXX
    WHERE ue.userid = u.id
)

ORDER BY
Lastname,
Firstname
于 2021-10-13T14:28:12.543 回答