Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
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 feedbackSuccess 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 Window Function Ranking
00:00
5 left

SQL Window Function Ranking

EasySQL · PostgreSQL

Problem

Accenture España wants to identify the highest-value customers in each sales region. Write a SQL query to rank customers by their total revenue within each region.

Requirements

  1. Aggregate revenue per region and customer_id.
  2. Rank customers within each region by total revenue, highest first.
  3. Use a window function to assign the rank.
  4. Return only customers with at least one completed order.

Schema

regions
ColumnTypeDescription
region_idPKINTPrimary key for the region
region_nameVARCHAR(100)Region name
customers
ColumnTypeDescription
customer_idPKINTPrimary key for the customer
customer_nameVARCHAR(100)Customer name
region_idINTRegion assigned to the customer
orders
ColumnTypeDescription
order_idPKINTPrimary key for the order
customer_idINTCustomer who placed the order
order_statusVARCHAR(20)Order status, such as completed or cancelled
order_amountDECIMAL(10,2)Revenue from the order
order_dateDATEOrder date
Tablesregionscustomersorders
Interviewer

Your question is SQL Window Function Ranking. 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.