AnalystPath

Top Three Food Trucks Per City

SQLHardSenior level~15 min

Problem

A street-food festival platform records sales `revenue` for each food truck across many stops. For every `city`, find the three food trucks with the highest **total revenue**. Break ties by `truck_name` alphabetically (A first). Output four columns: `city`, `first_truck`, `second_truck`, `third_truck`. Each truck cell must read as `truck_name (total_revenue)` (for example `TacoTide (320)`). If a city has fewer than three trucks, put the text `No runner up` for a missing second place and `No third place` for a missing third place. Order the result by `city` ascending.

Tables

Example rows — the live problem includes the full dataset.

TruckSales
sale_idcityrevenuetruck_name
1Austin120TacoTide
2Austin200TacoTide
3Austin150BunBros

Expected output

Your answer should return 3 rows with the columns city, first_truck, second_truck, third_truck.

Starter code (SQL)

SELECT *
FROM TruckSales;

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