0% found this document useful (0 votes)
4 views6 pages

Northwind More Business Questions

The document contains SQL queries designed to answer various business questions, including identifying the top 5 employees by total sales, calculating profit contributions of suppliers, and determining average sales per customer by country and category. Each query utilizes joins between relevant tables to aggregate sales data and profits. The results are ordered and limited to provide concise insights into sales performance and profitability.

Uploaded by

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

Northwind More Business Questions

The document contains SQL queries designed to answer various business questions, including identifying the top 5 employees by total sales, calculating profit contributions of suppliers, and determining average sales per customer by country and category. Each query utilizes joins between relevant tables to aggregate sales data and profits. The results are ordered and limited to provide concise insights into sales performance and profitability.

Uploaded by

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

Business Questions

2. Who are the top 5 employees by total sales they facilitated?

SELECT CONCAT(e.firstname, ' ', e.lastname) AS Name,

SUM((od.quantity * od.unitprice) * (1 - od.discount)) AS Total_Sales

FROM employee e

JOIN `order` o ON o.employeeid = e.employeeid

JOIN orderdetail od ON od.orderid = o.orderid

GROUP BY Name

ORDER BY Total_Sales DESC

LIMIT 5

;
Business Questions

SELECT de.fullname,

SUM(fs.revenue) AS Total_Sales

FROM factsale fs

JOIN dimemployee de ON de.employeeid = fs.employeeid

GROUP BY de.fullname

ORDER BY Total_Sales DESC

LIMIT 5

;
Business Questions
5. What is the profit contribution of each supplier over the last year?

SELECT s.companyname AS Shipper,

-- (od.quantity * od.unitprice * (1 - od.discount)) AS Total_Revenue,

-- (od.quantity * pc.costperunit) AS Total_Cost

SUM((od.quantity * od.unitprice * (1 - od.discount)) - (od.quantity * pc.costperunit)) AS


Total_Profit

FROM orderdetail od

JOIN `order` o ON od.orderid = o.orderid

JOIN product p ON od.productid = p.productid

JOIN productcost pc ON p.productid = pc.productid

JOIN supplier s ON s.supplierid = p.supplierid

WHERE YEAR(o.orderdate) = 2024

GROUP BY Shipper

ORDER BY Total_Profit DESC

;
Business Questions

SELECT ds.companyname AS Supplier,

SUM(fs.revenue - fs.cost) AS Profit

FROM factsale fs

JOIN dimsupplier ds ON fs.supplierid = ds.supplierid

JOIN dimdate d ON fs.orderdateid = d.dateid

WHERE d.year = 2024

GROUP BY Supplier

ORDER BY Profit DESC

;
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
;

You might also like