Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

SQL for Course Enrollment Metrics

MediumSQL · PostgreSQL00:00
Practice interviewer
In session
5 left
00:00

Your question is SQL for Course Enrollment Metrics. Start with the requirements and the three tables on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Patreon’s internal creator education catalog needs a report showing which active professors are associated with each department and which published courses they teach. Write a PostgreSQL query using the relationships among professors, departments, and courses.

Requirements

  1. Return every active professor, including professors with no published courses or no assigned department.
  2. Display the professor name, department name, number of published courses, and a comma-separated alphabetical list of published course titles.
  3. Show 0 and None when an active professor has no published courses.
  4. Order by published course count descending, then professor name ascending.

Schema

professors
ColumnTypeDescription
professor_idPKINTUnique professor identifier
professor_nameVARCHAR(100)Professor’s name
department_idINTReferences departments.department_id
is_activeBOOLEANWhether the professor is active
departments
ColumnTypeDescription
department_idPKINTUnique department identifier
department_nameVARCHAR(100)Department name
courses
ColumnTypeDescription
course_idPKINTUnique course identifier
course_titleVARCHAR(150)Course title
professor_idINTReferences professors.professor_id
statusVARCHAR(20)Course publication status
Tablesprofessorsdepartmentscourses
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results