Northwind More Business Questions
Northwind More Business Questions
FROM employee e
GROUP BY Name
LIMIT 5
;
Business Questions
SELECT de.fullname,
SUM(fs.revenue) AS Total_Sales
FROM factsale fs
GROUP BY de.fullname
LIMIT 5
;
Business Questions
5. What is the profit contribution of each supplier over the last year?
FROM orderdetail od
GROUP BY Shipper
;
Business Questions
FROM factsale fs
GROUP BY Supplier
;
Business Questions
6. What are the average sales per customer in each country and category?
SELECT c.country,
ca.categoryname,
SUM(od.quantity * od.unitprice * (1 - od.discount)) / COUNT(DISTINCT o.customerid)
AS Average_Sales_Per_Customer
FROM orderdetail od
JOIN `order` o ON od.orderid = o.orderid
JOIN customer c ON o.customerid = c.customerid
JOIN product p ON od.productid = p.productid
JOIN category ca ON p.categoryid = ca.categoryid
GROUP BY c.country,
ca.categoryname
ORDER BY c.country,
ca.categoryname
;
Business Questions
SELECT c.country,
ca.categoryname,
SUM(fs.revenue) / COUNT(DISTINCT fs.customerid) AS Average_Sales_Per_Customer
FROM factsale fs
JOIN dimcustomer c ON fs.customerid = c.customerid
JOIN dimcategory ca ON fs.categoryid = ca.categoryid
GROUP BY c.country,
ca.categoryname
ORDER BY c.country,
ca.categoryname
;