SQLSQL
#4

Conditional Categorization Using CASE WHEN in SQL

EasyZomato
Interview Question #4
Asked at Zomato

Given 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_idrestaurant_iddistance_kmorder_status
501122.4delivered
502145.8delivered
5031911.2delivered
Expected Output Structure3 rows
order_iddistance_kmpriority_level
5012.4Express Urban
5025.8Standard Metro
50311.2Extended Distance
Interview Context

Asked frequently in data analyst and business analyst technical rounds. Focus on clean filtering, optimal indexing usage, and unambiguous column selection.

SQLPostgreSQL 15
Ready to execute

Click "Run Query" or press Ctrl + Enter to test your query.

Output will be verified against the test dataset.

Chat with us