Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
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 feedbackCoaching1:1 coaching with people at your target companiesSuccess 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 Products by Sales Revenue
00:00
5 left

Top Products by Sales Revenue

EasySQL · PostgreSQL

Problem

NovaCart wants to identify its highest-revenue products from completed sales. Write a SQL query to return the top 10 products by total sales revenue.

Requirements

  1. Use only completed orders when calculating revenue.
  2. Compute product revenue as quantity * unit_price from order line items.
  3. Return each product's product_id, product_name, and total revenue.
  4. Sort by total revenue descending, then by product_id ascending to break ties.
  5. Return only the top 10 rows.

Schema

products
ColumnTypeDescription
product_idPKINTPrimary key for the product
product_nameVARCHAR(100)Display name of the product
categoryVARCHAR(50)Product category
orders
ColumnTypeDescription
order_idPKINTPrimary key for the order
customer_idINTIdentifier for the customer
order_dateDATEDate the order was placed
statusVARCHAR(20)Order lifecycle status
order_items
ColumnTypeDescription
order_item_idPKINTPrimary key for the order line
order_idINTReferences orders.order_id
product_idINTReferences products.product_id
quantityINTNumber of units purchased
unit_priceDECIMAL(10,2)Unit price captured at purchase time
Tablesproductsordersorder_items
Interviewer

Your question is Top Products by Sales Revenue. Start with the requirements and the three 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.