Last active
December 26, 2015 02:29
-
-
Save TakashiSasaki/7078878 to your computer and use it in GitHub Desktop.
Moodle 2.xでコースの参加者数を集計するためのMySQLに対するクエリ。
何度も何度も面倒なのでもうここにメモっておく。
「Moodleのコースにおけるユーザーへのロール割り当てに基づいた学生数と教員数の集計.sql」をビューにしようとしたらサブクエリが複数の行を返すって怒られた。
ンな事ないんだがなぁ。
VIEWをかましています。周囲のSQLerによるとSQL音痴のやることだとか。ごめんね。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT コースID AS courseid, コース名, コース省略名 AS 省略名, | |
(SELECT SUM(人数) FROM 集計_参加者数 WHERE コースID=courseid GROUP BY コースID) AS `参加者数`, | |
ifnull((SELECT 人数 FROM 集計_参加者数 WHERE ロール="Student" AND コースID=courseid),0) AS `学生権限の人数`, | |
ifnull((SELECT 人数 FROM 集計_参加者数 WHERE ロール="Teacher" AND コースID=courseid),0) AS `教員権限の人数` | |
FROM 集計_参加者数 | |
GROUP BY courseid |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT mdl_course.id, mdl_course.fullname, mdl_course.shortname, | |
mdl_enrol.id as enrolid, mdl_enrol.roleid, | |
mdl_user_enrolments.userid, | |
mdl_user.username | |
FROM mdl_course, mdl_enrol, mdl_user_enrolments, mdl_user | |
WHERE mdl_course.id=mdl_enrol.courseid | |
AND mdl_enrol.id=mdl_user_enrolments.enrolid | |
AND mdl_user.id=mdl_user_enrolments.userid |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT mdl_course.id AS コースID, | |
mdl_course.fullname AS コース名, mdl_course.shortname AS コース省略名, | |
COUNT(mdl_role_assignments.userid) AS 人数, | |
mdl_role.name AS ロール | |
FROM mdl_context, mdl_role_assignments, mdl_role, mdl_course | |
WHERE mdl_context.contextlevel=50 | |
AND mdl_context.id=mdl_role_assignments.contextid | |
AND mdl_role.id=mdl_role_assignments.roleid | |
AND mdl_course.id=mdl_context.instanceid | |
GROUP BY mdl_course.id, mdl_role_assignments.roleid |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment