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
| id | name | revenue | category |
|---|---|---|---|
| 1 | Laptop Pro | 45000 | Electronics |
| 2 | Coffee Maker | 12000 | Appliances |
| 3 | Wireless Mouse | 8000 | Electronics |
| 4 | Standing Desk | 28000 | Furniture |
| 5 | Headphones | 18000 | Electronics |
| 6 | Office Chair | 22000 | Furniture |
| 7 | Webcam | 6000 | Electronics |
Expected output (columns: name, revenue)
Laptop Pro|45000
Standing Desk|28000
Office Chair|22000
LIMIT 3returns 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"