`shopping_categories` is a category tree (`parent_id` NULL for top-level categories). For every LEAF category (one that is nobody's parent) build its breadcrumb from the top: names joined with ' > ' (e.g. 'Electronics > Audio > Headphones'). Return `cat_id`, `breadcrumb`, `depth` (top level = 1). Order by `breadcrumb`.
| Column | Type |
|---|---|
| cat_id | INTEGER |
| parent_id | INTEGER |
| cat_name | TEXT |
| cat_id | parent_id | cat_name |
|---|---|---|
| 1 | NULL | Electronics |
| 2 | 1 | Audio |
| 3 | 2 | Headphones |
| 4 | 2 | Speakers |
| 5 | 1 | Cameras |
| 6 | NULL | Home |
| 7 | 6 | Kitchen |
| cat_id | breadcrumb | depth |
|---|---|---|
| 3 | Electronics > Audio > Headphones | 3 |
| 4 | Electronics > Audio > Speakers | 3 |
| 5 | Electronics > Cameras | 2 |
| 7 | Home > Kitchen | 2 |
Solve it in the live editor on this page — run on sample data, then submit against hidden tests.
‹ De-duplicate Multi-Device Playback Logs · Normalize Artist Credits ›
{{ 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.