Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

SQL Top Three Products

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

Your question is SQL Top Three Products. Start with the requirements and the one table 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

QuantumBlack needs a simple sales summary for its AI and analytics offerings. Write a PostgreSQL query against the sales_transactions table to find the three products generating the highest sales revenue.

Requirements

  1. Calculate line revenue as quantity * unit_price and sum it for each product.
  2. Return the top three products, ordered from highest to lowest total revenue.

Schema

sales_transactions
ColumnTypeDescription
transaction_idPKINTEGERUnique transaction identifier
product_nameVARCHAR(100)Name of the QuantumBlack offering
quantityINTEGERNumber of units sold
unit_priceNUMERIC(10,2)Price charged per unit
sale_dateDATEDate of the transaction
Tablessales_transactions
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results