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
Rolling 7-Day Metric With Windows
00:00
5 left

Rolling 7-Day Metric With Windows

MediumSQL · PostgreSQL

Problem

Business Context

Amazon Seller Central needs a report showing which product categories generate the most completed order revenue for each seller.

Task

Write a PostgreSQL query that joins sellers, categories, and orders to rank each seller's categories by completed order revenue during January 2025.

Requirements

  1. Include only orders with status = 'Completed' and an order_date from 2025-01-01 through 2025-01-31.
  2. Calculate total revenue for each seller and category using SUM(order_amount).
  3. Use DENSE_RANK() to rank categories separately within each seller, with the highest revenue ranked first.
  4. Return the seller, category, total revenue, and category rank. Sort results by seller and rank. Rows with category_rank <= 2 represent each seller's top two revenue ranks, including ties.

Schema

sellers
ColumnTypeDescription
seller_idPKINTUnique seller identifier
seller_nameVARCHAR(100)Seller display name
categories
ColumnTypeDescription
category_idPKINTUnique product category identifier
category_nameVARCHAR(100)Product category name
orders
ColumnTypeDescription
order_idPKINTUnique order identifier
seller_idINTReferences sellers.seller_id
category_idINTReferences categories.category_id
order_dateDATEDate the order was placed
statusVARCHAR(20)Order fulfillment status
order_amountNUMERIC(12,2)Revenue attributed to the order
Tablesorderssellerscategories
Interviewer

Your question is Rolling 7-Day Metric With Windows. 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.