Skip to content

Instantly share code, notes, and snippets.

@ogabrielguerra
Created September 25, 2020 01:15
Show Gist options
  • Save ogabrielguerra/c8073aff6fb1c405f691a615693a5ed0 to your computer and use it in GitHub Desktop.
Save ogabrielguerra/c8073aff6fb1c405f691a615693a5ed0 to your computer and use it in GitHub Desktop.
SQL Script - Course Manager Queries
-- COUNT APPLICATIONS BY USER
SELECT ca.id_user, u.name,
COUNT(ca.id_user) as num_applications
FROM course_application ca, user u
WHERE ca.id_user = u.id
GROUP BY ca.id_user, u.name;
-- COUNT COURSES BY USER OF ID 1
SELECT ca.id, ca.id_user, ca.id_course,
c.title, u.name, u.email, ca.application_date
FROM course_application ca , course c, user u
WHERE ca.id_user = u.id
AND ca.id_course = c.id
AND ca.id_user = 1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment