Hi there,
I want to count the # of views users of two specific roles in their courses, but the count seems to grab the # of users in that role and not the page hits. Can you see where I'm going wrong?
/*
Name:
Course and Unit page hits by enrolled students and teachers.
Description:
Counts the number of times a course page is hit by enrolled students and teachers.
*/
select
lsl.courseid,
c.fullname course,
lsl.action,
lsl.target,
count(lsl.id) hits,
(select count(lsl.id) from mdl_role_assignments ra where ra.contextid = ct.id and ra.roleid = 5) studenthits
(select count(lsl.id) from mdl_role_assignments ra where ra.contextid = ct.id and ra.roleid = 9) spnethits
from mdl_logstore_standard_log lsl
join mdl_course c on c.id = lsl.courseid
and c.id != 1
join mdl_context ct on ct.instanceid = c.id
and ct.contextlevel = 50
where lsl.action = 'viewed'
and lsl.target = 'course'
group by lsl.courseid
Expected outcome:
Actual outcome:
courseid | course | action | target | hits | studenthits | spnethits | |
---|---|---|---|---|---|---|---|
2 | TDC Unit Tempate | viewed | course | 125 | 3 | 0 | |
3 | TDC Course Template | viewed | course | 2 | 2 | 0 | |
4 | Dummy Course | viewed | course | 5 | 0 | 0 | |
5 | TDC Unit No Students | viewed | course | 2 | 0 | 0 | |
6 | Baking | viewed | course | 3 | 0 | 1 | |
7 | Cookies | viewed | course | 8 | 0 | 0 | |
8 | Apples | viewed | course | 21 | 2 | 1 | |
9 | Test course | viewed | course | 2 | 2 | 1 |