SELECT s.sale_id, c.customer_name, s.sale_date, s.total_amount FROM sales s JOIN customers c ON s.customer_id = c.customer_id;
-- 3. List sales with product details:
SELECT s.sale_id, p.product_name, s.quantity, s.total_amount FROM sales s JOIN products p ON s.product_id = p.product_id;
-- 4. Count the number of products:
SELECT COUNT(*) AS product_count FROM products;
-- 5. Find customers who made a purchase in a specific date range:
SELECT DISTINCT c.customer_name FROM customers c JOIN sales s ON c.customer_id = s.customer_id WHERE s.sale_date BETWEEN '2024-03-01' AND '2024-03-31';
-- 6. Identify sales with high quantities (quantity > 2):
SELECT sale_id, quantity FROM sales WHERE quantity > 2;
-- 7. Display the total sales amount for each customer:
SELECT c.customer_name, SUM(s.total_amount) AS total_sales FROM customers c JOIN sales s ON c.customer_id = s.customer_id GROUP BY c.customer_name;
-- 8. Find the average quantity of products sold:
SELECT AVG(quantity) AS avg_quantity FROM sales;
-- 9. Show the earliest sale date for each product:
SELECT p.product_name, MIN(s.sale_date) AS earliest_sale_date FROM products p JOIN sales s ON p.product_id = s.product_id GROUP BY p.product_name;
-- 10. Display customers who have not made a purchase:
SELECT customer_name FROM customers WHERE customer_id NOT IN (SELECT customer_id FROM sales);