Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

SQL Window Functions for Deadlines

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

Your question is SQL Window Functions for Deadlines. Start with the requirements and the four 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

Business Context

Newton School of Technology wants to identify students who may need support because they are repeatedly missing project deadlines.

Task

Write a PostgreSQL query that finds every run of at least two consecutive missed project deadlines for each student. A deadline is missed when the student has no submission or submits after the deadline.

Requirements

  1. Join students, project assignments, projects, and submissions.
  2. Use window functions to detect consecutive missed projects according to sequence_number.
  3. Treat missing submissions and late submissions as missed deadlines.
  4. Return one row per consecutive run, including the student, number of missed deadlines, first and last deadline, and project names.
  5. Exclude runs containing fewer than two consecutive missed deadlines, and order results by student and run start.

Schema

students
ColumnTypeDescription
student_idPKINTUnique student identifier
student_nameVARCHAR(100)Student's full name
projects
ColumnTypeDescription
project_idPKINTUnique project identifier
project_nameVARCHAR(150)Project title
sequence_numberINTChronological project sequence
deadlineDATEProject submission deadline
assignments
ColumnTypeDescription
assignment_idPKINTUnique assignment identifier
student_idINTAssigned student
project_idINTAssigned project
submissions
ColumnTypeDescription
submission_idPKINTUnique submission identifier
assignment_idINTAssignment associated with the submission
submitted_atDATEDate the project was submitted
Tablesstudentsprojectsassignmentssubmissions
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results