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 for Top Performing Retailers
00:00
5 left

SQL for Top Performing Retailers

HardSQL · PostgreSQL

Problem

Write a SQL query to identify the top 10% of performing retailers over the last fiscal quarter, accounting for seasonal sales spikes.

Use the most recently completed fiscal quarter. Treat seasonally adjusted sales as each sale's net sales divided by the seasonal index for its calendar month. Include retailers with no qualifying sales when determining the 10% cutoff.

Output

  1. One row per selected retailer with retailer_id, retailer_name, adjusted_sales, and performance_rank
  2. Include the highest-performing 10%, rounding the cutoff up when necessary
  3. Order by adjusted_sales descending, then retailer_id ascending

Schema

fiscal_quarters
ColumnTypeDescription
quarter_idPKINTFiscal quarter identifier
quarter_nameVARCHAR(20)Fiscal quarter label
start_dateDATEFirst date in the fiscal quarter
end_dateDATELast date in the fiscal quarter
is_last_completedBOOLEANWhether this is the most recently completed quarter
retailers
ColumnTypeDescription
retailer_idPKINTRetailer identifier
retailer_nameVARCHAR(100)Retailer name
regionVARCHAR(50)Retailer operating region
is_activeBOOLEANWhether the retailer is currently active
retailer_sales
ColumnTypeDescription
sale_idPKINTSale identifier
retailer_idINTRetailer associated with the sale
sale_dateDATESale date
net_salesDECIMAL(12,2)Net sales amount after adjustments
seasonal_indices
ColumnTypeDescription
calendar_monthPKINTCalendar month number
seasonal_indexDECIMAL(6,3)Seasonality multiplier for the month
index_sourceVARCHAR(50)Source of the seasonal index
Tablesfiscal_quartersretailersretailer_salesseasonal_indices
Interviewer

Your question is SQL for Top Performing Retailers. Start with the requirements and the four 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.