You are working as a Data Engineer for an e-commerce platform. The business team wants a quick overview of customer engagement by counting how many orders each customer has placed. You are given the following table: orders order_id (INT) – Unique identifier for each order customer_id (INT) – Identifier for the customer order_date (DATE) – Date when the order was placed Task: Write a SQL query to calculate the total number of orders placed by each customer . Expected Output: customer_id total_orders The result should have one row per customer.
Table Setup (SQL Schema)
-- DDL: Create table
CREATE TABLE orders (
order_id INT PRIMARY KEY,
customer_id INT,
order_date DATE
);
-- DML: Insert sample data
INSERT INTO orders (order_id, customer_id, order_date) VALUES
(1, 301, '2024-01-01'),
(2, 302, '2024-01-02'),
(3, 301, '2024-01-03'),
(4, 303, '2024-01-04'),
(5, 302, '2024-01-05'),
(6, 301, '2024-01-06'),
(7, 304, '2024-01-07'),
(8, 303, '2024-01-08'),
(9, 305, '2024-01-09'),
(10, 302, '2024-01-10');