Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Top 5 Loans by Region
00:00
5 left

Top 5 Loans by Region

MediumSQL · PostgreSQL

Problem

Write a query to find the top 5 loans by balance within each geographical region.

Use the loans table. Exclude rows with a missing region or balance. Ties should be resolved by the smallest loan_id.

Output

  1. One row per selected loan, with geographical_region, loan_id, and balance.
  2. Include no more than five loans per region.
  3. Order by geographical_region, then balance descending, then loan_id ascending.

Schema

loans
ColumnTypeDescription
loan_idPKINTUnique loan identifier
geographical_regionVARCHAR(100)Geographical region associated with the loan
balanceDECIMAL(14,2)Outstanding loan balance
Tablesloans
Interviewer

Your question is Top 5 Loans by Region. Start with the requirements and the one table 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
You need to log in / sign up to run or submit.Ln 1
Run your query to see results here.