Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Top Products Overall
00:00
5 left

Top Products Overall

MediumSQL · PostgreSQL

Problem

Write a SQL query to find the top five products by sales at Enova International.

Use the sales amount recorded for each transaction to calculate total sales for each product. Return only products with recorded product names, ordered from highest total sales to lowest, with product name as the tie-breaker.

Output

  1. One row per product.
  2. Columns: product_name and total_sales.
  3. Include the five products with the highest total sales.
  4. Order by total_sales descending, then product_name ascending.

Schema

product_sales
ColumnTypeDescription
sale_idPKINTUnique identifier for the sale transaction
product_nameVARCHAR(100)Name of the product sold
sale_amountNUMERIC(12,2)Recorded sales amount for the transaction
Tablesproduct_sales
Interviewer

Your question is Top Products Overall. Start with the requirements and the one table 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
You need to log in / sign up to run or submit.Ln 1
Run your query to see results here.