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
Rank Rows Within Each Group
00:00
5 left

Rank Rows Within Each Group

EasySQL · PostgreSQL

Problem

RBC branch operations wants to identify the highest-balance active accounts at each branch. Write a PostgreSQL query that joins account records to RBC branches and ranks eligible accounts within each branch using a window function.

Requirements

  1. Include only accounts whose status is Active and whose current_balance is not NULL.
  2. Use RANK() with PARTITION BY branch_id, ordering balances from highest to lowest.
  3. Preserve ties, so accounts with equal balances receive the same rank.
  4. Return branch details, account details, balance, and rank, ordered by branch and rank.

Schema

branches
ColumnTypeDescription
branch_idPKINTEGERUnique RBC branch identifier
branch_nameVARCHAR(100)RBC branch name
provinceVARCHAR(50)Canadian province containing the branch
accounts
ColumnTypeDescription
account_idPKINTEGERUnique account identifier
branch_idINTEGERRBC branch associated with the account
account_typeVARCHAR(30)Account product type
statusVARCHAR(20)Current account status
current_balanceNUMERIC(12,2)Current balance of the account
Tablesbranchesaccounts
Interviewer

Your question is Rank Rows Within Each Group. 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.