You are working as a Data Engineer for an e-commerce platform. The business team wants to understand when each customer made their first purchase . You are given a 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 order_amount (NUMERIC) – Total amount of the order Task: Write a SQL query to return the first order date for each customer . Expected Output: customer_id first_order_date 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,
order_amount NUMERIC
);
-- DML: Insert sample data
INSERT INTO orders (order_id, customer_id, order_date, order_amount) VALUES
(1, 101, '2024-01-05', 120.50),
(2, 102, '2024-01-07', 75.00),
(3, 101, '2024-02-10', 200.00),
(4, 103, '2024-01-03', 50.00),
(5, 102, '2024-03-15', 150.00),
(6, 101, '2024-01-02', 90.00),
(7, 104, '2024-02-20', 300.00),
(8, 103, '2024-02-01', 80.00),
(9, 104, '2024-01-25', 220.00),
(10, 105, '2024-03-01', 60.00);