Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Trending in AI
Hot
Agentic AI EngineerForward-Deployed EngineerGenAI EngineerAI Architect
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
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess 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
Start free
Window Functions SQL Case
00:00
5 left

Window Functions SQL Case

MediumSQL · PostgreSQL

Problem

Tell me about a time you used SQL window functions to solve a business problem, and walk me through your approach step by step.

Use the customers, loans, and payments tables. Return monthly metrics for completed payments only. Include rows with NULL payment amounts and treat those amounts as zero.

Output

  1. One row per loan and payment month.
  2. Columns: loan_id, customer_name, payment_month, monthly_paid, payment_count, previous_month_paid, and cumulative_paid.
  3. Exclude months without completed payments. Order by loan_id, then payment_month ascending.

Schema

customers
ColumnTypeDescription
customer_idPKINTUnique customer identifier
customer_nameVARCHAR(100)Customer full name
loans
ColumnTypeDescription
loan_idPKINTUnique loan identifier
customer_idINTCustomer who owns the loan
payments
ColumnTypeDescription
payment_idPKINTUnique payment identifier
loan_idINTLoan associated with the payment
payment_dateDATEDate the payment was recorded
amountNUMERIC(12,2)Payment amount
statusVARCHAR(40)Payment processing status
Tablescustomersloanspayments
Interviewer

Whenever you're ready, walk me through your approach or go straight to the code. The requirements and the three tables are in the Question tab.

Sign up free to run or submit. Log in
CodePostgreSQL
Sign up free to run your code. Your draft is saved.Run with a free accountLog inLn 1
Run your query to see results here.