Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
SQL Query Writing for Students
00:00
5 left

SQL Query Writing for Students

HardSQL · PostgreSQL

Problem

Huron Consulting Group's learning analytics team needs a consolidated performance view for students whose name is exactly xyz. Write one PostgreSQL query that returns every matching student, including students without enrollments or assessment results.

Requirements

  1. Use a multi-level CTE pipeline and LAG to evaluate score progression within each student-course history.
  2. Calculate each student's total assessment score, treating missing scores as zero.
  3. Return distinct enrolled course names as an alphabetically ordered comma-separated list.
  4. Return the number of enrolled courses and the number of score improvements over the prior assessment.
  5. Preserve matching students with no enrollment through LEFT JOIN operations and order the final output by student_id.

Representative Sample Data

students: (1, 'xyz'), (2, 'xyz'), (3, 'Amina Patel')
enrollments: (1001, 1, 101), (1002, 1, 102), (1003, 3, 103)
courses: (101, 'PostgreSQL Optimization'), (102, 'Data Strategy')
assessments: (5001, 1001, '2026-01-10', 78), (5002, 1001, '2026-02-10', 85), (5003, 1002, '2026-01-15', 91), (5004, 1002, '2026-02-15', NULL)

Schema

students
ColumnTypeDescription
student_idPKINTUnique student identifier
student_nameVARCHAR(100)Student's displayed name
emailVARCHAR(255)Student email address
enrollments
ColumnTypeDescription
enrollment_idPKINTUnique enrollment identifier
student_idINTReferences students.student_id
course_idINTReferences courses.course_id when available
enrollment_statusVARCHAR(20)Enrollment state
courses
ColumnTypeDescription
course_idPKINTUnique course identifier
course_nameVARCHAR(150)Course title
course_categoryVARCHAR(50)Course subject category
assessments
ColumnTypeDescription
assessment_idPKINTUnique assessment identifier
enrollment_idINTReferences enrollments.enrollment_id
assessment_dateDATEDate the assessment was recorded
scoreINTAssessment score from 0 to 100
Tablesstudentsenrollmentscoursesassessments
Interviewer

Your question is SQL Query Writing for Students. Start with the requirements and the four tables in the Question tab.

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.
CodePostgreSQL
Sign up free to run your codeLog inLn 1
Run your query to see results here.