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: Top Categories by GMV Concentration
00:00
5 left

SQL: Top Categories by GMV Concentration

HardSQL · PostgreSQL

Problem

Business Context

Movate's analytics team wants to identify product categories whose annual GMV is highly concentrated in a short seasonal period.

Task

Write a PostgreSQL query for calendar year 2024 that returns the top five product categories where at least 60% of annual GMV occurs in any two consecutive calendar months.

Requirements

  1. Include all twelve months for every category, treating months without completed orders as zero GMV.
  2. Exclude orders outside 2024 and orders whose order_status is not completed.
  3. Calculate annual GMV and every two-month consecutive GMV total using window functions.
  4. Keep categories where the largest two-month total is at least 60% of annual GMV.
  5. Return the top five qualifying categories ranked by annual GMV descending, including the first month of the peak pair and its concentration percentage.

Schema

product_categories
ColumnTypeDescription
category_idPKINTUnique product category identifier
category_nameVARCHAR(100)Product category name
orders
ColumnTypeDescription
order_idPKINTUnique order identifier
category_idINTProduct category associated with the order
order_dateDATEDate on which the order was placed
gmvNUMERIC(12,2)Gross merchandise value for the order
order_statusVARCHAR(20)Order processing status
Tablesproduct_categoriesorders
Interviewer

Your question is SQL: Top Categories by GMV Concentration. 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.