Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Fastest Mastery Segment SQL

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

Your question is Fastest Mastery Segment SQL. 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

Khan Academy wants to identify learners who reach skill mastery most efficiently. Write a PostgreSQL query that finds the fastest 5% of learners based on the elapsed time between their first practice attempt and their first recorded mastery.

Requirements

  1. Calculate each learner's elapsed time to mastery for every skill with a qualifying mastery event.
  2. Summarize each learner using their average hours to mastery and count of mastered skills.
  3. Exclude learners without a qualifying mastery event. Treat mastery as an event where mastery_level = 'mastered'.
  4. Rank eligible learners by average mastery time in ascending order and return the fastest 5%. Round average hours to two decimal places.
  5. Return learner_id, learner_name, mastered_skills, avg_hours_to_mastery, rank_position, and eligible_learner_count.

Schema

learners
ColumnTypeDescription
learner_idPKINTUnique Khan Academy learner identifier
learner_nameVARCHAR(100)Display name of the learner
practice_attempts
ColumnTypeDescription
attempt_idPKINTUnique practice attempt identifier
learner_idINTLearner who made the attempt
skill_nameVARCHAR(100)Khan Academy skill practiced
attempted_atTIMESTAMPTimestamp when the practice attempt occurred
skill_mastery_events
ColumnTypeDescription
mastery_event_idPKINTUnique mastery event identifier
learner_idINTLearner associated with the mastery event
skill_nameVARCHAR(100)Khan Academy skill whose mastery status changed
mastery_levelVARCHAR(30)Recorded status, such as in_progress or mastered
mastered_atTIMESTAMPTimestamp when the status was recorded
Tableslearnerspractice_attemptsskill_mastery_events
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results