AnalystPath

Top Earning Market Stall

SQLEasyJunior level~15 min

Problem

A farmers market records every purchase made at its stalls.

Table: stall
+-------------+---------+
| Column Name | Type |
+-------------+---------+
| stall_id | int |
| produce | varchar |
| list_cents | int |
+-------------+---------+
stall_id is the primary key. Each row describes a stall and the produce it sells.

Table: purchase
+-------------+------+
| Column Name | Type |
+-------------+------+
| vendor_id | int |
| stall_id | int |
| shopper_id | int |
| sold_on | date |
| units | int |
| revenue | int |
+-------------+------+
This table may contain duplicate rows. Each row records one purchase made by a vendor.

Write a solution that reports the vendor(s) with the highest total revenue across all their purchases. If several vendors tie for the highest total, report all of them. Return the result in any order with a single column vendor_id.

Tables

Example rows — the live problem includes the full dataset.

stall
stall_idproducelist_cents
1Heirloom1000
2Honeycrisp800
3Cherries1400
purchase
vendor_idstall_idshopper_idsold_onunitsrevenue
1112021-01-2122000
1222021-02-171800
2232021-06-021800

Expected output

Your answer should return 2 rows with the columns vendor_id.

Starter code (SQL)

SELECT *
FROM stall;

Solve this SQL question free

Write SQL and run it instantly in your browser — even on your phone. No signup needed to try.

Solution & explanation

Create a free account to unlock the optimal solution, a step-by-step explanation, and the hidden test cases that grade your answer.

Sign up free to unlock

Related SQL questions