Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
Top Product Lines by Revenue
00:00
5 left

Top Product Lines by Revenue

EasySQL · PostgreSQL

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
Interviewer

Your question is Top Product Lines by Revenue. 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
Sign up free to run your codeLog inLn 1
Run your query to see results here.