SQL
All Top 50 SQL Interview Questions#4
Conditional Categorization Using CASE WHEN in SQL
EasyZomatoInterview Question #4
Asked at ZomatoGiven an `orders` table, categorize each order into a `priority_level` based on delivery distance in kilometers: <= 3km as 'Express Urban', between 3.01 and 8km as 'Standard Metro', and > 8km as 'Extended Distance'. Return `order_id`, `distance_km`, and `priority_level`.
Input Table: orders
3 rows preview| order_id | restaurant_id | distance_km | order_status |
|---|---|---|---|
| 501 | 12 | 2.4 | delivered |
| 502 | 14 | 5.8 | delivered |
| 503 | 19 | 11.2 | delivered |
Expected Output Structure3 rows
| order_id | distance_km | priority_level |
|---|---|---|
| 501 | 2.4 | Express Urban |
| 502 | 5.8 | Standard Metro |
| 503 | 11.2 | Extended Distance |
Interview Context
Asked frequently in data analyst and business analyst technical rounds. Focus on clean filtering, optimal indexing usage, and unambiguous column selection.
PostgreSQL 15
Ready to execute
Click "Run Query" or press Ctrl + Enter to test your query.
Output will be verified against the test dataset.