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 Contact Categories Rolling 30 Days
00:00
5 left

Top Contact Categories Rolling 30 Days

MediumSQL · PostgreSQL

Problem

Write a query using window functions and joins to identify the top three customer contact categories by order volume over a rolling 30-day period.

Use the provided orders, customer_contacts, and contact_categories tables. Count distinct orders with non-null contact dates, using an inclusive 30-day window consisting of the reporting date and prior 29 calendar days. Return exactly three categories when at least three qualify, with alphabetical category order breaking ties.

Output

  1. One row per qualifying category and reporting date, with report_date, category_name, rolling_30_day_order_volume, and category_rank.
  2. Include only the top three categories for each reporting date, ordered by report_date, category_rank, and category_name.

Schema

orders
ColumnTypeDescription
order_idPKINTUnique order identifier
customer_idINTCustomer who placed the order
order_dateDATEDate the order was placed
customer_contacts
ColumnTypeDescription
contact_idPKINTUnique customer contact record
order_idINTOrder associated with the contact
category_idINTContact category referenced by the record
contact_dateDATEDate of the customer contact
contact_categories
ColumnTypeDescription
category_idPKINTUnique contact category identifier
category_nameVARCHAR(100)Customer contact category name
Tablesorderscustomer_contactscontact_categories
Interviewer

Your question is Top Contact Categories Rolling 30 Days. 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.