diff --git a/part1.sql b/part1.sql new file mode 100644 index 0000000..af0cc95 --- /dev/null +++ b/part1.sql @@ -0,0 +1,3 @@ +SELECT customerName AS 'Customer Name', CONCAT(lastName, ', ', firstName) AS 'Sales Rep' +FROM customers +JOIN employees on customers.salesRepEmployeeNumber = employees.employeeNumber; \ No newline at end of file diff --git a/part2.sql b/part2.sql new file mode 100644 index 0000000..8a6f681 --- /dev/null +++ b/part2.sql @@ -0,0 +1,15 @@ +SELECT p.productName AS 'Product Name', +sum(od.quantityOrdered) AS 'Total # Ordered', +sum(od.quantityOrdered*od.priceEach) AS 'Total Sale' +FROM products p +JOIN orderdetails AS od ON p.productCode=od.productCode GROUP BY od.productCode; + + +-- SELECT productName AS 'Product Name', +-- (SELECT sum(quantityOrdered) FROM orderdetails group by productCode HAVING products.productCode=orderdetails.productCode) AS 'Total # Ordered', +-- (SELECT sum(quantityOrdered*priceEach) FROM orderdetails group by productCode HAVING products.productCode=orderdetails.productCode) AS 'Total Sale' +-- FROM products; + + + + diff --git a/part3.sql b/part3.sql new file mode 100644 index 0000000..a4a3d15 --- /dev/null +++ b/part3.sql @@ -0,0 +1 @@ +SELECT status AS 'Order Status', count(STATUS) AS '# Orders' FROM orders GROUP BY STATUS; \ No newline at end of file diff --git a/part4.sql b/part4.sql new file mode 100644 index 0000000..34d97f0 --- /dev/null +++ b/part4.sql @@ -0,0 +1,5 @@ +SELECT pl.productLine AS 'Product Line', +SUM(od.quantityOrdered) AS '# Orders' +FROM productlines pl +JOIN products p ON pl.productLine = p.productLine +JOIN orderdetails od ON p.productCode = od.productCode GROUP BY od.productCode; \ No newline at end of file diff --git a/part5.sql b/part5.sql new file mode 100644 index 0000000..ec4ef67 --- /dev/null +++ b/part5.sql @@ -0,0 +1,7 @@ +SELECT CONCAT(e.lastName, ', ', e.firstName) AS 'Sales Rep', +sum(od.quantityOrdered) AS '# Orders', +IFNULL(sum(od.quantityOrdered*od.priceEach), 0.00) AS 'Total Sales' +FROM employees e +JOIN customers c ON c.salesRepEmployeeNumber=e.employeeNumber +JOIN orders o ON o.customerNumber=c.customerNumber +JOIN orderdetails od ON od.orderNumber=o.orderNumber GROUP BY e.lastName ORDER BY 'Total Sales'; \ No newline at end of file diff --git a/part6.sql b/part6.sql new file mode 100644 index 0000000..0080b53 --- /dev/null +++ b/part6.sql @@ -0,0 +1,2 @@ +SELECT DATE_FORMAT(paymentDate, '%M') AS 'Month', YEAR(paymentDate) AS 'Year', sum(amount) AS 'Payments Received' +FROM payments GROUP BY MONTH(paymentDate), YEAR(paymentDate); \ No newline at end of file