Skip to main content

Posts

Showing posts from January, 2024

SQL Question and Answer - Interview Fresher as well as Experience

CREATE TABLE orders (     id INT PRIMARY KEY,     customer_id INT,     courier_id INT,     seller_id INT,     order_timestamp_utc DATETIME,     amount FLOAT,     city_id INT ); INSERT INTO orders (id, customer_id, courier_id, seller_id, order_timestamp_utc, amount, city_id) VALUES     (1, 101, 201, 301, '2023-01-15 10:30:00', 50.00, 401),     (2, 102, 202, 302, '2023-01-16 11:45:00', 75.50, 402),     (3, 103, 203, 303, '2023-01-17 12:15:00', 120.25, 403),     (4, 104, 204, 304, '2023-01-18 09:00:00', 30.75, 404),     (5, 105, 205, 305, '2023-01-19 14:20:00', 90.80, 405); Q.1 Which hour has the highest average order volume per day? Your output should have the hour which satisfies that condition, and average order volume. Approach 1: With CTE WITH RankedHours AS ( SELECT DATEPART(HOUR, order_timestamp_utc) AS hour_of_day, AVG(amount) AS average_order_...