Default Image

Top 3 Products by Revenue

Top 3 Products by Revenue Easy
You have two tables: products and order_items.

Write a SQL query to find the top 3 products by total revenue (quantity × unit_price).

Return: product_name, total_revenue.
Order by total_revenue descending.
products order_items
CREATE TABLE products (
    product_id   INT PRIMARY KEY,
    product_name VARCHAR(100) NOT NULL,
    category     VARCHAR(50)
);

CREATE TABLE order_items (
    item_id      INT PRIMARY KEY,
    product_id   INT NOT NULL,
    quantity     INT NOT NULL,
    unit_price   DECIMAL(10,2) NOT NULL
);
INSERT INTO products VALUES
(1, 'Laptop Pro',     'Electronics'),
(2, 'Wireless Mouse', 'Electronics'),
(3, 'Standing Desk',  'Furniture'),
(4, 'USB-C Hub',      'Electronics'),
(5, 'Ergonomic Chair','Furniture');

INSERT INTO order_items VALUES
(1, 1, 5,  1299.00),
(2, 1, 3,  1299.00),
(3, 2, 20,   29.99),
(4, 3, 2,   499.00),
(5, 4, 15,   49.99),
(6, 5, 4,   399.00),
(7, 2, 10,   29.99),
(8, 3, 8,   499.00),
(9, 1, 2,  1299.00);

Log in to see your submissions.

  1. JOIN products with order_items. SUM(quantity * unit_price) gives revenue. Use LIMIT 3.
SQL
Write a query and click Run to see results.