Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Window Function for Second-Highest
00:00
5 left

Window Function for Second-Highest

MediumSQL · PostgreSQL

Problem

Write a SQL query using window functions to find the second-highest mortgage application volume by region.

Use the regions and mortgage_applications tables. Include regions with no applications when calculating volumes, and return every region tied at the second-highest volume.

Output

  1. One row per qualifying region with region_name and application_volume.
  2. Include only regions at the second-highest volume rank.
  3. Order results alphabetically by region_name.

Schema

regions
ColumnTypeDescription
region_idPKINTUnique identifier for a geographic region
region_nameVARCHAR(100)Name of the geographic region
mortgage_applications
ColumnTypeDescription
application_idPKINTUnique identifier for a mortgage application
region_idINTRegion associated with the application
application_dateDATEDate the mortgage application was submitted
application_statusVARCHAR(30)Current processing status of the application
Tablesregionsmortgage_applications
Interviewer

Your question is Window Function for Second-Highest. 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
You need to log in / sign up to run or submit.Ln 1
Run your query to see results here.