order_lines has one row per order line (product_id, quantity). Total the units sold per product and return the product or products tied for the highest total. Output columns: product_id, units_sold. Order by product_id ascending.
| Column | Type |
|---|---|
| product_id | INTEGER |
| quantity | INTEGER |
| product_id | quantity |
|---|---|
| 10 | 5 |
| 10 | 3 |
| 20 | 10 |
| 30 | 4 |
| 30 | 6 |
| product_id | units_sold |
|---|---|
| 20 | 10 |
| 30 | 10 |
Solve it in the live editor on this page — run on sample data, then submit against hidden tests.
{{ totalCount }} questions in the style asked at Amazon, Microsoft, Google, Meta, Flipkart and more — {{ hardPct }}% Hard. Write SQL in a real database engine in your browser, run it on sample data, then evaluate against hidden tests.
Company tags show where this type of question is commonly reported in interviews. Questions, data and solutions are written by TechTown.
{{ cur.statement }}
No submissions yet. Press Evaluate to submit your query.
{{ solutionSql }}
{{ out.error }}
You have solved your 3 free questions — nice work! Log in (free) to unlock all 150 questions, keep your streak and appear on the leaderboard.