Last active
October 23, 2023 12:59
-
-
Save michaelmeneses/60fc740ad81e8150fe0d8aed49253ca4 to your computer and use it in GitHub Desktop.
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 cfield.id as fieldid, cdata.value, count(cdata.value) as total | |
FROM mdl_user_enrolments ue | |
JOIN mdl_enrol e ON e.id = ue.enrolid | |
JOIN mdl_course c ON c.id = e.courseid | |
JOIN mdl_course_categories cat ON cat.id = c.category | |
JOIN mdl_competency_coursecomp ccomp ON ccomp.courseid = c.id | |
JOIN mdl_competency comp ON comp.id = ccomp.competencyid | |
JOIN mdl_context ctx ON ctx.instanceid = c.id AND ctx.contextlevel = 50 | |
JOIN mdl_customfield_data cdata ON cdata.contextid = ctx.id | |
JOIN mdl_customfield_field cfield ON cfield.id = cdata.fieldid AND cfield.shortname = 'casa' | |
WHERE NULLIF(cdata.value, '')::int > 0 | |
AND ue.userid = 97237 | |
AND comp.id IN (2997,3472,4385,4669,4981,5799,6228,8622,9688,10301,10302,15781,17214,19778,1312) | |
GROUP BY cfield.id, cdata.value | |
ORDER BY count(*) DESC | |
LIMIT 1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment