Last active
December 14, 2015 15:59
-
-
Save mikebuchanon/5112347 to your computer and use it in GitHub Desktop.
find count of read and unread posts given userid and 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 d.id AS discussion, | |
f.name AS name, | |
sum(case when r.postid is null then 1 else 0 end) as unread_posts, | |
sum(case when r.postid is null then 0 else 1 end) as read_posts | |
FROM mdl_course c | |
JOIN mdl_forum_discussions d on d.course = c.id | |
JOIN mdl_forum f on f.id = d.forum | |
JOIN mdl_forum_posts p ON p.discussion = d.id | |
LEFT JOIN mdl_forum_read r ON r.postid = p.id | |
WHERE c.id = 3 | |
and r.userid=4 | |
group by d.id, f.name; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment