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 for Monthly Aggregates
00:00
5 left

SQL for Monthly Aggregates

HardSQL · PostgreSQL

Problem

DigitalOcean's Financial Analytics team needs a monthly view of customer satisfaction for active paid accounts. Write a PostgreSQL query for January through April 2025.

Requirements

  1. Return one row for every calendar month in the reporting period, including months with no valid responses.
  2. Include only customers with an active paid subscription during each month and exclude internal accounts.
  3. For each customer and month, retain only the most recent CSAT response.
  4. Exclude NULL and out-of-range scores, where valid CSAT scores are integers from 1 through 5.
  5. Return the monthly average score, the previous month's average, and the month-over-month change. Round score values to two decimal places.
  6. Sort results chronologically.

Schema

customers
ColumnTypeDescription
customer_idPKINTUnique customer identifier
customer_nameVARCHAR(120)Customer account name
segmentVARCHAR(30)Customer business segment
is_internalBOOLEANWhether the account is an internal DigitalOcean account
subscriptions
ColumnTypeDescription
subscription_idPKINTUnique subscription identifier
customer_idINTReferenced customer
plan_nameVARCHAR(60)DigitalOcean subscription plan
started_atDATESubscription start date
ended_atDATESubscription end date, if ended
csat_responses
ColumnTypeDescription
response_idPKINTUnique survey response identifier
customer_idINTCustomer submitting the response
submitted_atTIMESTAMPResponse submission timestamp
scoreINTCustomer satisfaction score from 1 through 5
response_channelVARCHAR(30)Channel used to submit the response
Tablescustomerssubscriptionscsat_responses
Interviewer

Your question is SQL for Monthly Aggregates. Start with the requirements and the three 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.