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
Top 5 Student Segments Query
00:00
5 left

Top 5 Student Segments Query

MediumSQL · PostgreSQL

Problem

Given this schema, write a query to identify the top 5 segments of students by enrollment volume at Southern New Hampshire University.

Count distinct active or completed enrollments in the 2024-2025 academic year, using the student's segment that was effective at the start of the enrollment term. Exclude canceled enrollments and segments with no qualifying enrollments.

Output

  1. One row per selected segment with segment_name and enrollment_volume
  2. Return exactly five rows, ordered by enrollment volume descending, then segment name ascending to break ties

Schema

academic_terms
ColumnTypeDescription
term_idPKINTUnique academic term identifier
term_nameVARCHAR(50)Display name of the academic term
academic_yearVARCHAR(20)Academic year containing the term
term_start_dateDATEFirst date of the academic term
students
ColumnTypeDescription
student_idPKINTUnique student identifier
student_typeVARCHAR(30)Broad student classification
student_segments
ColumnTypeDescription
student_segment_idPKINTUnique segment membership record
student_idINTStudent assigned to the segment
segment_idINTAssigned student segment
effective_start_dateDATEDate when the assignment begins
effective_end_dateDATEDate when the assignment ends
enrollments
ColumnTypeDescription
enrollment_idPKINTUnique enrollment identifier
student_idINTStudent associated with the enrollment
term_idINTAcademic term for the enrollment
enrollment_statusVARCHAR(20)Current enrollment status
segments
ColumnTypeDescription
segment_idPKINTUnique segment identifier
segment_nameVARCHAR(80)Student segment name
Tablesacademic_termsstudentsstudent_segmentsenrollmentssegments
Interviewer

Your question is Top 5 Student Segments Query. Start with the requirements and the five 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.