You are working as a Data Engineer for an e-commerce platform. The marketing team wants to identify loyal customers who have placed multiple orders. 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 find customers who have placed more than 2 orders . Expected Output: customer_id order_count (total number of orders placed by the customer) The result should be sorted by order_count in descending 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, 201, '2024-03-01', 100.00),
(2, 202, '2024-03-02', 200.00),
(3, 201, '2024-03-03', 150.00),
(4, 203, '2024-03-04', 300.00),
(5, 202, '2024-03-05', 120.00),
(6, 201, '2024-03-06', 80.00),
(7, 204, '2024-03-07', 250.00),
(8, 202, '2024-03-08', 90.00),
(9, 203, '2024-03-09', 60.00),
(10, 201, '2024-03-10', 110.00);