diff --git a/original-readme.docx b/original-readme.docx deleted file mode 100644 index 33e1bd4..0000000 Binary files a/original-readme.docx and /dev/null differ diff --git a/part1.sql b/part1.sql new file mode 100644 index 0000000..8e05920 --- /dev/null +++ b/part1.sql @@ -0,0 +1,8 @@ +--Write a query to display each customer’s name (asCustomer Name) alongside the name of the employee who is responsible for that customer’s orders. +--The employee name should be in a single Sales Rep column formatted as lastName, firstName. The output should be sorted alphabetically by customer name. + +SELECT p.productName AS 'Product Name', o.quantityOrdered AS 'Total # Ordered', (o.quantityOrdered * o.priceEach) AS 'Total Sale' +FROM products AS p +INNER JOIN orderdetails as o +ON p.productCode=o.productCode +ORDER BY (o.quantityOrdered * o.priceEach) DESC; \ No newline at end of file diff --git a/part2.sql b/part2.sql new file mode 100644 index 0000000..b50de9e --- /dev/null +++ b/part2.sql @@ -0,0 +1,11 @@ +--Determine which products are most popular with our customers. +--For each product, list the total quantity ordered along with the total sale generated (total quantity ordered * priceEach) for that product. +--The column headers should be Product Name, Total # Ordered and Total Sale. +--List the products by Total Sale descending. + + +SELECT p.productName AS 'Product Name', o.quantityOrdered AS 'Total # Ordered', (o.quantityOrdered * o.priceEach) AS 'Total Sale' +FROM products AS p +INNER JOIN orderdetails as o +ON p.productCode=o.productCode +ORDER BY Total Sale DESC; \ No newline at end of file diff --git a/part3.sql b/part3.sql new file mode 100644 index 0000000..10784b2 --- /dev/null +++ b/part3.sql @@ -0,0 +1,9 @@ +--Write a query which lists order status and the # of orders with that status. +--Column headers should be Order Status and # Orders. +--Sort alphabetically by status. + +SELECT o.status AS 'Order Status', ord.quantityOrdered AS '# Orders' +FROM orderdetails as ord +INNER JOIN orders AS o +ON ord.orderNumber=o.orderNumber +ORDER BY o.status ASC; \ No newline at end of file diff --git a/part4.sql b/part4.sql new file mode 100644 index 0000000..d5174e6 --- /dev/null +++ b/part4.sql @@ -0,0 +1,9 @@ +--Write a query to list, for each product line, the total # of products sold from that product line. +--The first column should be Product Line and the second should be # Sold. +--Order by the second column descending. +-- COUNT +SELECT DISTINCT p.productLine AS 'Product Line', o.quantityOrdered AS '# Sold' +FROM products AS p +INNER JOIN orderdetails AS o +ON p.productCode=o.productCode +ORDER BY o.quantityOrdered DESC; \ No newline at end of file diff --git a/part5.sql b/part5.sql new file mode 100644 index 0000000..2afd3e5 --- /dev/null +++ b/part5.sql @@ -0,0 +1,20 @@ +--For each employee who represents customers, output the total # of orders that employee’s customers have placed alongside the total sale amount of those orders. +--The employee name should be output as a single column named Sales Rep formatted as lastName, firstName. +--The second column should be titled # Orders and the third should be Total Sales. +--Sort the output by Total Sales descending. +--Only (and all) employees with the job title Sales Rep should be included in the output, and if the employee made no sales the Total Sales should display as 0.00. + +SELECT CONCAT(e.lastName, ', ', e.firstName) AS 'Sales Rep', ord.quantityOrdered AS '# Orders', (ord.quantityOrdered * ord.priceEach) AS 'Total Sales' +COUNT (o.orderNumbers) AS totalOrders, IFNULL((sum(ord.quantityOrdered * ord.priceEach)), 0) AS 'Total Sales' +FROM employees AS e +LEFT JOIN customers AS c +ON e.employeeNumber=c.salesRepEmployeeNumber +FROM customers AS c +LEFT JOIN orders AS o +ON c.customerNumber=o.customerNumber +FROM orders AS o +LEFT JOIN orderdetails AS ord +ON o.orderNumber=ord.orderNumber +WHERE e.jobTitle='Sales Rep' +ORDER BY (ord.quantityOrdered * ord.priceEach) DESC +GROUP BY CONCAT(e.lastName, ', ', e.firstName) \ No newline at end of file diff --git a/part6.sql b/part6.sql new file mode 100644 index 0000000..2a989dc --- /dev/null +++ b/part6.sql @@ -0,0 +1,9 @@ +--Your product team is requesting data to help them create a bar-chart of monthly sales since the company’s inception. +--Write a query to output the month (January, February, etc.), 4-digit year, and total sales for that month. +--The first column should be labeled Month, the second Year, and the third should be Payments Received. +--Values in the third column should be formatted as numbers with two decimals – for example: 694,292.68. + +SELECT monthName(paymentDate) AS 'Month', EXTRACT(Year FROM paymentDate) AS 'Year', amount AS 'Payments Received' +FROM payments +GROUP BY monthName(paymentDate), Year +ORDER BY paymentDate ASC; \ No newline at end of file