0% found this document useful (0 votes)
6 views2 pages

DWM - Task 5

Uploaded by

princesslaude18
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views2 pages

DWM - Task 5

Uploaded by

princesslaude18
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Task 5: Final Analysis

Customer Spending Report: Show customer id, full name, total


orders, amount spent, and most recent purchase.
SELECT
c.customer_id,
c.first_name || ‘ ‘ || c.last_name AS Full_Name,
COUNT(o.order_id) AS Total_Orders,
SUM(oi.item_total) AS Amount_Spent,
MAX(o.order_date) AS Most_Recent_Purchase
FROM
Customers c
JOIN
Orders o ON c.customer_id = o.customer_id
JOIN
Order_Items oi ON o.order_id = oi.order_id
GROUP BY
c.customer_id, Full_Name
ORDER BY
c.customer_id;

Top Products by Sales: List the top 3 products by total sales


amount.
SELECT
p.product_id,
p.product_name,
SUM(oi.item_total) AS Total_Sales_Amount
FROM
Products p
JOIN
Order_Items oi ON p.product_id = oi.product_id
GROUP BY
p.product_id, p.product_name
ORDER BY
Total_Sales_Amount DESC
LIMIT 3;

Total Monthly Revenue: Show the total revenue generated per


month.
SELECT
strftime('%Y-%m', o.order_date) AS sales_month,
SUM(oi.item_total) AS total_revenue
FROM
Orders o
JOIN
Order_Items oi ON o.order_id = oi.order_id
GROUP BY
sales_month
ORDER BY
sales_month;
Average Order Value by Month: Calculate the average order
value for each month.
SELECT
Strftime(‘%Y-%m’, p.payment_date) AS sales_month,
AVG(p.payment_amount) AS average_order_value
FROM
Payments p
JOIN
Orders o ON p.order_id = o.order_id
GROUP BY
Sales_month
ORDER BY
Sales_month;

Frequent Shoppers: Identify customers who have placed more


than 3 orders.
SELECT
c.customer_id,
c.first_name,
c.last_name,
COUNT(o.order_id) AS total_orders
FROM
Customers c
JOIN
Orders o ON c.customer_id = o.customer_id
GROUP BY
c.customer_id, c.first_name, c.last_name
HAVING
COUNT(o.order_id) > 3;

REFLECTION
This SQL exercise showed me that the real challenge isn’t just knowing
individual SQL commands, but skillfully combining them. While simple
joins were easy, tasks like calculating average order value needed careful
use of subqueries and aggregate functions ( SUM , AVG , COUNT ) to get
accurate results.

This experience greatly improved my data analysis skills. I learned to


extract meaningful information efficiently from large datasets. SQL’s
joins, aggregate functions, and subqueries let me do this much more
effectively than using other methods. Also, using these tools correctly
was vital for getting accurate results and making sure the data was
handled properly. Finally, the SQL approach is scalable it can handle much
larger datasets without needing major changes to the queries. In short,
success depends not just on knowing SQL commands, but on mastering
how to combine them to solve complex data problems.

You might also like