我需要SQL专家的帮助。当我执行以下查询时,我得到了我想要的大多数信息,即用户在Moodle中完成的全部课程。问题是当我添加一个课程列作为结果显示时,例如c.shortname,记录开始被复制。我想这是由于我的JOIN之一引起的,但是我尝试移动它们却没有发现问题。谢谢。
SELECT username, FROM_UNIXTIME(mdl_customcert_issues.timecreated, '%d-%m-%Y') AS date_created, ue.userid
FROM mdl_user u
JOIN mdl_customcert_issues ON mdl_customcert_issues.userid = u.id
JOIN mdl_user_enrolments ue ON ue.userid = mdl_customcert_issues.userid
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 AND ct.contextlevel = 50
JOIN mdl_course c ON c.id = ct.instanceid AND e.courseid = c.id
我期望的是这样的:
用户名|用户创建日期|活动1已完成|活动2已完成|课程1 |