SQL CODES
SQL CODES
WITH order_time AS (
SELECT
ord.order_time,
COUNT(ord.order_id) AS total_orders,
CASE
WHEN ord.order_time >= '00:00:00' AND ord.order_time <= '11:59:00' THEN
'Morning'
WHEN ord.order_time >= '12:00:00' AND ord.order_time <= '17:00:00' THEN
'Afternoon'
ELSE 'Evening'
END AS time_of_day
FROM
restaurant_orders.order_details AS ord
WHERE ord.item_id IS NOT NULL
GROUP BY
ord.order_time
)
SELECT
time_of_day,
SUM(total_orders) AS total_orders
FROM order_time
GROUP BY time_of_day
ORDER BY total_orders DESC;