Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Second-Highest Sales by Region

MediumSQL · PostgreSQL00:00
Practice interviewer
In session
5 left
00:00

Your question is Second-Highest Sales by Region. Start with the requirements and the two tables on the right.

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.

Problem

Write a query to find the second-highest sales amount in each region for Benjamin Moore.

Use the provided regional and sales data. Return only regions with at least two distinct non-null sales amounts.

Output

  1. One row per qualifying region
  2. Columns: region_name, second_highest_sales_amount
  3. Sort alphabetically by region_name

Schema

regions
ColumnTypeDescription
region_idPKINTUnique identifier for a sales region
region_nameVARCHAR(100)Benjamin Moore sales region name
sales_transactions
ColumnTypeDescription
sale_idPKINTUnique identifier for a sales transaction
region_idINTRegion associated with the transaction
sales_amountDECIMAL(12,2)Amount recorded for the transaction
sale_dateDATEDate of the sale
Tablesregionssales_transactions
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results