SQL QuestSQL Interview Questions › Window Functions

Top 3 Banks Per State by Assets

HardProQuerying BasicsWindow Functions

For each state, rank its banks by total_assets and return the top 3 per state. Use a window function with PARTITION BY state. Show state, name, total_assets, rank_in_state. Filter to rank <= 3. Order by state, then rank_in_state.

Solve it in the browser editor →

Runs on SQLite in your browser, graded against the expected result, no signup. A wrong answer gets a diagnosis, not just "incorrect".

Schema

institutions

certnamecitystatezipcharter_classestablished_datetotal_assetstotal_depositstotal_equityoffice_countbank_class
628JPMorgan Chase Bank, National AssociationColumbusOH43240801/01/1824375266200026978420003359360005335N
3510Bank of America, National AssociationCharlotteNC282021304410/17/1904263682300021019680002462500003840N
7213Citibank, National AssociationSioux FallsSD57108146106/16/181218364360001465300000176530000958N

Expected output: Top 3 banks in each state

Hint

This is a Pro challenge — the hint, the step-by-step tutor and the reference solution open in the app.

Concepts

SELECT Window Functions RANK PARTITION BY

Practise the topic: SQL practice questions · Window function practice · Ranking function practice · Advanced SQL interview questions

In these company practice sets

JPMorgan · Goldman Sachs · Bloomberg

A SQL Quest challenge matched to patterns reported for these companies — not a question any of them has published.

Related questions

Cumulative Distinct Customers Over TimeHard · FreeSalary Rank Within DepartmentHard · FreeRunning Total RevenueHard · FreeYear-over-Year GrowthHard · Free7-Day Rolling Revenue AverageHard · FreeMulti-CTE Revenue PipelineHard · Free

Where would this cost you points in an interview?

Ten questions, no signup: a Skillmap across nine SQL skills and the one to fix first.

Take the readiness test