You are working as a Data Engineer for an e-commerce company. The business wants to understand how much revenue each customer has generated. You are given a table called orders with the following structure: order_id (INTEGER): Unique identifier for each order customer_id (INTEGER): 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 calculate the total revenue generated by each customer . Expected Output: customer_id total_revenue (sum of all order amounts per customer) The result should be sorted by customer_id in ascending order.
Table Setup (SQL Schema)
-- DDL: Create table
CREATE TABLE orders (
order_id INTEGER PRIMARY KEY,
customer_id INTEGER,
order_date DATE,
order_amount NUMERIC(10, 2)
);
-- DML: Insert sample data
INSERT INTO orders (order_id, customer_id, order_date, order_amount) VALUES
(1, 101, '2024-01-01', 250.00),
(2, 102, '2024-01-02', 150.00),
(3, 101, '2024-01-03', 300.00),
(4, 103, '2024-01-04', 200.00),
(5, 102, '2024-01-05', 100.00),
(6, 101, '2024-01-06', 50.00),
(7, 104, '2024-01-07', 400.00),
(8, 103, '2024-01-08', 150.00),
(9, 104, '2024-01-09', 250.00),
(10, 102, '2024-01-10', 200.00);