SQL 1
SQL 1
2. To group the different entries for veg and non-veg using CASE statement
and then find the number of orders of each food_type i.e. veg and non-veg:
SELECT t2.food_type_new, SUM(t1.quantity) AS item_quantity
FROM orders_items t1
LEFT JOIN (
SELECT item_id,
CASE
WHEN food_type LIKE 'veg%' THEN 'veg'
ELSE 'non-veg'
END AS food_type_new
FROM food_items
) t2 ON t1.item_id = t2.item_id
GROUP BY t2.food_type_new;
3. To find the number of orders received by each restaurant from the dataset:
SELECT r.restaurant_name, r.id, r.cuisine, SUM(quantity) as item_quantity
FROM restaurants r
LEFT JOIN food_items fi ON r.id = fi.restaurant_id
LEFT JOIN orders_items o ON fi.item_id = o.item_id
GROUP BY r.id
ORDER BY item_quantity;
4. To find the number of restaurants that received no orders from the dataset:
SELECT r.restaurant_name, r.restaurant_id, r.cuisine, SUM(quantity) as
item_quantity
FROM restaurants r
LEFT JOIN food_items fi ON r.restaurant_id = fi.restaurant_id
LEFT JOIN orders_items o ON fi.item_id = o.item_id
GROUP BY r.restaurant_id
HAVING item_quantity IS NULL
ORDER BY item_quantity;