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
Write SQL queries using ranking window functions
00:00
5 left

Write SQL queries using ranking window functions

HardSQL · PostgreSQL

Problem

Write SQL queries using ranking window functions (RANK and DENSE_RANK) together with aggregates, joins and CASE statements

Asked in the SQL technical round stage. This was a 1-hour all-SQL round with two AVPs.

Output

  1. Return one row per Barclays trading desk, including desks with no qualifying trades.
  2. Include desk_id, desk_name, total_settled_value, settled_trade_count, performance_band, value_rank, and value_dense_rank.
  3. Include only trades with status SETTLED from 2025-01-01 through 2025-03-31. Rows with a NULL trade value contribute nothing to the total.
  4. Order by total settled value descending, then desk ID ascending.

Schema

desks
ColumnTypeDescription
desk_idPKINTUnique trading desk identifier
desk_nameVARCHAR(60)Trading desk name
employees
ColumnTypeDescription
employee_idPKINTUnique employee and trader identifier
employee_nameVARCHAR(100)Employee name
desk_idINTAssigned trading desk identifier
trades
ColumnTypeDescription
trade_idPKINTUnique trade identifier
trader_idINTTrader identifier
trade_dateDATETrade execution date
statusVARCHAR(40)Trade processing status
trade_valueNUMERIC(14,2)Monetary value of the trade
Tablesdesksemployeestrades
Interviewer

Your question is Write SQL queries using ranking window functions. 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.