Skip to content

Instantly share code, notes, and snippets.

@kevincolten
Created November 7, 2016 21:54
Show Gist options
  • Save kevincolten/235ae1d7db713b1d79512814c78da8b0 to your computer and use it in GitHub Desktop.
Save kevincolten/235ae1d7db713b1d79512814c78da8b0 to your computer and use it in GitHub Desktop.
Campus Manager Report Queries
SELECT idn, first_name, last_name, email, phone, COUNT(users.email) as courses
FROM users
INNER JOIN registrations ON users.id = registrations.user_id
GROUP BY users.email
HAVING COUNT(users.email) < 3 AND COUNT(users.email) > 1
ORDER BY courses DESC, cast(idn as Number) ASC;
SELECT idn, first_name, last_name, email, phone, city
FROM users
JOIN registrations ON users.id = registrations.user_id
JOIN courses ON registrations.course_id = courses.id
JOIN terms ON terms.id = courses.term_id
JOIN locations ON term.location_id = locations.id
GROUP BY users.email;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment