-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_teacher by courses
123 lines (71 loc) · 2.88 KB
/
get_teacher by courses
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
SELECT c.id, c.fullname, u.firstname,u.lastname, u.username, u.email, r.name as cours_role
FROM mdl_course c
JOIN mdl_context ct ON c.id = ct.instanceid
JOIN mdl_role_assignments ra ON ra.contextid = ct.id
JOIN mdl_user u ON u.id = ra.userid
JOIN mdl_role r ON r.id = ra.roleid
WHERE r.id = '3';
SELECT DISTINCT u.firstname, u.lastname, u.email ,c.fullname, c.shortname, rl.name as Role
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
JOIN mdl_role As rl ON rl.id = ra.roleid
WHERE u.username = 'username'
ORDER BY c.startdate ASC;
--Get student enrolment count by course
SELECT c.shortname, COUNT(DISTINCT u.id) AS Students
FROM mdl_role_assignments AS ra
JOIN mdl_context AS ctx ON ra.contextid = ctx.id AND ctx.contextlevel = 50
JOIN mdl_user AS u ON u.id = ra.userid
JOIN mdl_course AS c ON ctx.instanceid = c.id
WHERE ra.roleid = 5
AND c.shortname like '%2023%'
GROUP BY c.shortname;
SELECT COUNT(u.id) AS Students
FROM mdl_role_assignments AS ra
JOIN mdl_context AS ctx ON ra.contextid = ctx.id AND ctx.contextlevel = 50
JOIN mdl_user AS u ON u.id = ra.userid
JOIN mdl_course AS c ON ctx.instanceid = c.id
--JOIN mdl_user_enrolments as ue on u.id = ue.userid
--JOIN mdl_enrol as e on e.id = ue.enrolid
WHERE ra.roleid = 5
AND c.shortname like '%2023%'
--AND e.enrol like 'manual'
select c.shortname, g.name, u.username
from mdl_course as c
inner join mdl_groups as g on c.id = g.courseid
inner join mdl_groups_members as gm on gm.groupid = g.id
inner join mdl_user as u on gm.userid = u.id
where c.shortname like '%2023%' --and c.shortname like 'PL100%'
--group by c.shortname, g.name
order by c.shortname, g.name;
--Get student enrolment count by course
SELECT c.shortname, COUNT(DISTINCT u.id) AS Students
FROM mdl_role_assignments AS ra
JOIN mdl_context AS ctx ON ra.contextid = ctx.id AND ctx.contextlevel = 50
JOIN mdl_user AS u ON u.id = ra.userid
JOIN mdl_course AS c ON ctx.instanceid = c.id
WHERE ra.roleid = 5
AND c.shortname like '%2023%'
GROUP BY c.shortname;
SELECT COUNT(u.id) AS Students
FROM mdl_role_assignments AS ra
JOIN mdl_context AS ctx ON ra.contextid = ctx.id AND ctx.contextlevel = 50
JOIN mdl_user AS u ON u.id = ra.userid
JOIN mdl_course AS c ON ctx.instanceid = c.id
--JOIN mdl_user_enrolments as ue on u.id = ue.userid
--JOIN mdl_enrol as e on e.id = ue.enrolid
WHERE ra.roleid = 5
AND c.shortname like '%2023%'
--AND e.enrol like 'manual'
;
select * from mdl_course;
select * from mdl_groups_members;
select c.shortname, g.name, u.username
from mdl_course as c
inner join mdl_groups as g on c.id = g.courseid
inner join mdl_groups_members as gm on gm.groupid = g.id
inner join mdl_user as u on gm.userid = u.id
where c.shortname like '%2023%' --and c.shortname like 'PL100%'
--group by c.shortname, g.name
order by c.shortname, g.name;