Skip to content

Instantly share code, notes, and snippets.

WITH subject_points AS (
SELECT
subject.id subject_id,
subject.name subject_name,
achievement.user_id user_id,
SUM(achievement.points) points
FROM subjects_subject_topics subject_topic
LEFT JOIN subjects_subject subject
ON subject.id = subject_topic.subject_id
LEFT JOIN subjects_topic topic