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: Month-over-Month Service Trends
00:00
5 left

SQL: Month-over-Month Service Trends

HardSQL · PostgreSQL

Problem

Write a SQL query to compare monthly service request volume and completion rate by site, using a window function to show month-over-month change.

Use the service_sites and service_requests tables. Treat a request as completed when completed_at is not NULL. Include every site for every month in the submitted-request date range, including months with no requests.

Output

  1. One row per site and calendar month, with columns site_id, site_name, month, request_volume, completion_rate, volume_mom_change, and completion_rate_mom_change.
  2. Show completion rate as a percentage, and month-over-month changes as current month minus prior month. Use NULL for changes when no prior month exists.
  3. Order by site_id, then month ascending.

Schema

service_sites
ColumnTypeDescription
site_idPKINTUnique identifier for a service site
site_nameVARCHAR(100)Display name of the service site
service_requests
ColumnTypeDescription
request_idPKINTUnique identifier for a service request
site_idINTSite associated with the request
submitted_atDATEDate the request was submitted
completed_atDATEDate the request was completed
Tablesservice_sitesservice_requests
Interviewer

Your question is SQL: Month-over-Month Service Trends. Start with the requirements and the two 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.