In this video, I'll show you how to use a simple SQL query to find customers who have placed more than one order in the last month.
This information can be used to identify your best customers and target them with special promotions or offers.
I'll also walk you through the steps of running the query and interpreting the results.
Create Table:
CREATE TABLE customers (
customer_id INT PRIMARY KEY,
customer_name VARCHAR(50)
);
-- Create the orders table
CREATE TABLE orders (
order_id INT PRIMARY KEY,
customer_id INT,
order_date DATE,
order_total DECIMAL(10, 2)
);
Insert data:
-- Insert sample data into the customers table
INSERT INTO customers (customer_id, customer_name)
VALUES (1, 'John Doe'),
(2, 'Jane Smith'),
(3, 'Alice Johnson'),
(4, 'Robert Brown');
-- Insert sample data into the orders table
INSERT INTO orders (order_id, customer_id, order_date, order_total)
VALUES (1, 1, '2023-05-15', 100.00),
(2, 1, '2023-05-20', 75.50),
(3, 2, '2023-05-12', 200.00),
(4, 3, '2023-05-25', 50.00),
(5, 3, '2023-06-01', 120.75),
(6, 4, '2023-06-10', 80.50),
(7, 1, '2023-06-25', 80.50),
(8, 1, '2023-06-24', 80.50),
✅ To learn more, visit us at https://visionforanalytics.com/
✅ Join our WhatsApp group to ask any questions you may have!https://chat.whatsapp.com/LTLprgdpVIh...
✅ Subscribe to the YouTube channel here:
/ @sqlcoder