Company: Stripe | Difficulty: medium
Find customers with the highest total order value.
For each customer, calculate total revenue by multiplying quantity by price for every valid order line. Ignore rows with a NULL customer name, quantity, or price. Zero quantity and zero price are valid values.
quantity
price
Return the columns in this exact order: customer_name and total.
customer_name
total
Sort by total revenue in descending order. If two customers have the same total, sort their names in descending alphabetical order.
orders
order_id
Soylent generates 1000.00 in revenue, Acme Corp generates 500.00, Globex generates 450.00, and Initech generates 300.00. The customers are listed from highest to lowest total revenue.
DROP TABLE IF EXISTS orders; CREATE TABLE orders ( order_id INT, customer_name VARCHAR(100), quantity INT, price DECIMAL(10,2) ); INSERT INTO orders VALUES (1,'Soylent',2,500.00), (2,'Acme Corp',5,100.00), (3,'Globex',3,150.00), (4,'Initech',3,100.00);
← All SQL Challenges · Stripe Questions · Learn SQL Free