Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

SQL Join and Completion Rates

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

Your question is SQL Join and Completion Rates. 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

Cengage wants a category-level view of learner progress across its digital learning products. Write a PostgreSQL query that joins users, enrollments, and courses to calculate enrollment and completion metrics by course category.

Requirements

  1. Join the three tables using their key relationships.
  2. Treat an enrollment as completed when completed_at is not NULL.
  3. Return total enrollments, completed enrollments, and completion rate as a percentage, rounded to two decimal places.
  4. Sort categories by completion rate descending, then category name ascending.

Schema

users
ColumnTypeDescription
user_idPKINTUnique learner identifier
full_nameVARCHAR(255)Learner's full name
emailVARCHAR(255)Learner email address
enrollments
ColumnTypeDescription
enrollment_idPKINTUnique enrollment identifier
user_idINTReferences users.user_id
course_idINTReferences courses.course_id
completed_atTIMESTAMPTimestamp when the learner completed the course
courses
ColumnTypeDescription
course_idPKINTUnique course identifier
course_nameVARCHAR(255)Course title
categoryVARCHAR(100)Course subject category
Tablesusersenrollmentscourses
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results