Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Top Product Lines by Revenue

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

Your question is Top Product Lines by Revenue. 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

NetApp's BI team needs a ranked view of product-line performance for completed sales recorded during 2025. Write a PostgreSQL query to identify the top three NetApp product lines by revenue.

Requirements

  1. Join product_lines to sales using product_line_id.
  2. Include only sales with status = 'completed' and a sale_date in calendar year 2025.
  3. Calculate revenue as units_sold * unit_price, treating NULL numeric inputs as zero.
  4. Return exactly the top three product lines, ordered from highest to lowest revenue. Use a deterministic tie-breaker by product-line name.

Representative Sample Data

product_lines includes ONTAP, AFF, FAS, StorageGRID, BlueXP, Keystone, ASA, and Cloud Volumes ONTAP. sales contains multiple rows per product line, cancelled and out-of-period sales, NULL values, and one orphaned product-line ID.

Schema

product_lines
ColumnTypeDescription
product_line_idPKINTUnique product-line identifier
product_line_nameVARCHAR(80)NetApp product-line name
sales
ColumnTypeDescription
sale_idPKINTUnique sale identifier
product_line_idINTLogical reference to the product line
units_soldINTNumber of units sold
unit_priceNUMERIC(12,2)Price per unit
sale_dateDATEDate on which the sale was recorded
statusVARCHAR(20)Sale processing status
Tablesproduct_linessales
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results