EasySQL

Top 3 Products by Revenue

SQLDatabases

Write a SQL query that returns the name and revenue of the 3
best-selling products, ordered by revenue descending.

Table: `products`

idnamerevenuecategory
1Laptop Pro45000Electronics
2Coffee Maker12000Appliances
3Wireless Mouse8000Electronics
4Standing Desk28000Furniture
5Headphones18000Electronics
6Office Chair22000Furniture
7Webcam6000Electronics

Expected output (columns: name, revenue)

Laptop Pro|45000
Standing Desk|28000
Office Chair|22000

LIMIT 3 returns at most 3 rows from the result.

Sample tests

Test #1Top 3 from 7 products
Input: "CREATE TABLE products (id INTEGER, name TEXT, revenue INTEGER, category TEXT);\nINSERT INTO products VALUES\n (1, 'Laptop Pro', 45000, 'Electronics'),\n (2, 'Coffee Maker', 12000, 'Appliances'),\n (3, 'Wireless Mouse', 8000, 'Electronics'),\n (4, 'Standing Desk', 28000, 'Furniture'),\n (5, 'Headphones', 18000, 'Electronics'),\n (6, 'Office Chair', 22000, 'Furniture'),\n (7, 'Webcam', 6000, 'Electronics');"
Output: "Laptop Pro|45000\nStanding Desk|28000\nOffice Chair|22000"