From 18ba6887e26a8b75fb2b835db99a0353ecf9743e Mon Sep 17 00:00:00 2001 From: monicadeshmukh Date: Mon, 13 Jul 2020 10:33:23 -0400 Subject: [PATCH 1/6] sqlJoinsPart1.sql --- sqlJoinsPart1.sql | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 sqlJoinsPart1.sql diff --git a/sqlJoinsPart1.sql b/sqlJoinsPart1.sql new file mode 100644 index 0000000..c7a592c --- /dev/null +++ b/sqlJoinsPart1.sql @@ -0,0 +1,10 @@ +/*Part 1 +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 c.customerName AS "Customer Name", CONCAT (e.lastName, ' ', e.firstname) AS "Sales Rep" +FROM customers c INNER JOIN employees e +ON c.salesRepEmployeeNumber = e.employeeNumber +ORDER BY c.customerName DESC; From 1888f569753d53f854191255a3a69996f584fd37 Mon Sep 17 00:00:00 2001 From: monicadeshmukh Date: Mon, 13 Jul 2020 10:35:02 -0400 Subject: [PATCH 2/6] order changed to ASC to diaplay results alphabetically --- sqlJoinsPart1.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sqlJoinsPart1.sql b/sqlJoinsPart1.sql index c7a592c..747966b 100644 --- a/sqlJoinsPart1.sql +++ b/sqlJoinsPart1.sql @@ -7,4 +7,4 @@ The output should be sorted alphabetically by customer name.*/ SELECT c.customerName AS "Customer Name", CONCAT (e.lastName, ' ', e.firstname) AS "Sales Rep" FROM customers c INNER JOIN employees e ON c.salesRepEmployeeNumber = e.employeeNumber -ORDER BY c.customerName DESC; +ORDER BY c.customerName ASC; From 6966a9a64869a37203dcf239d3c7450a9b905cff Mon Sep 17 00:00:00 2001 From: monicadeshmukh Date: Mon, 13 Jul 2020 12:18:00 -0400 Subject: [PATCH 3/6] sqlJoinsPart2.sql --- sqlJoinsPart2.sql | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 sqlJoinsPart2.sql diff --git a/sqlJoinsPart2.sql b/sqlJoinsPart2.sql new file mode 100644 index 0000000..e5590b0 --- /dev/null +++ b/sqlJoinsPart2.sql @@ -0,0 +1,33 @@ +/*Part 2 +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", SUM(od.quantityOrdered) AS "Total # Ordered", (SUM(od.quantityOrdered)*od.priceEach) AS "Total Sale" +FROM products p +JOIN orderdetails od +ON p.productCode = od.productCode +GROUP BY p.productName +ORDER BY SUM(od.quantityOrdered)*od.priceEach DESC; + +/*SELECT p.productName AS "Product Name", COUNT(p.productCode) AS "Total # Ordered", (COUNT(p.productCode) * od.priceEach) AS "Total Sale" +FROM customers c, orders o, orderdetails od, products p +WHERE c.customerNumber = o.customerNumber +AND o.orderNumber = od.orderNumber +AND od.productCode = p.productCode +GROUP BY p.productCode +ORDER BY "Total Sale" DESC;*/ +/*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 od +ON p.productCode = od.productCode +GROUP BY p.productCode +ORDER BY "ToTal Sale" DESC;*/ +/*SELECT productcode, quantityOrdered FROM orderdetails +GROUP BY productCode +HAVING productCode = "S10_1678";*/ +/*SELECT productcode, sum(quantityOrdered) FROM orderdetails +WHERE productcode = "S10_1678";*/ + From 9eb5b70f4524e3233f30d33b605ae4dd416ead33 Mon Sep 17 00:00:00 2001 From: monicadeshmukh Date: Mon, 13 Jul 2020 13:08:29 -0400 Subject: [PATCH 4/6] sqlJoinsPart3.sql --- sqlJoinsPart3.sql | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 sqlJoinsPart3.sql diff --git a/sqlJoinsPart3.sql b/sqlJoinsPart3.sql new file mode 100644 index 0000000..0e61d1c --- /dev/null +++ b/sqlJoinsPart3.sql @@ -0,0 +1,8 @@ +/*Part 3 +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 STATUS AS "Order Status", COUNT(ordernumber) AS "# of orders" +FROM orders +GROUP BY STATUS +ORDER BY STATUS ASC; \ No newline at end of file From d71367f254ef8406bd7c7616eb2711dfab67d58a Mon Sep 17 00:00:00 2001 From: monicadeshmukh Date: Mon, 13 Jul 2020 13:16:07 -0400 Subject: [PATCH 5/6] sqlJoinsPart4.sql --- sqlJoinsPart4.sql | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 sqlJoinsPart4.sql diff --git a/sqlJoinsPart4.sql b/sqlJoinsPart4.sql new file mode 100644 index 0000000..bf84d97 --- /dev/null +++ b/sqlJoinsPart4.sql @@ -0,0 +1,8 @@ +/*Part 4 +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.*/ +SELECT productline AS "Product Line", COUNT(productcode) AS "# Sold" +FROM products +GROUP BY productline +ORDER BY COUNT(productcode) DESC; \ No newline at end of file From d44b7b77681497636db73f1ff941c227dacccc6f Mon Sep 17 00:00:00 2001 From: monicadeshmukh Date: Mon, 13 Jul 2020 23:23:52 -0400 Subject: [PATCH 6/6] sqlJoinsPart6.sql --- sqlJoinsPart6.sql | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 sqlJoinsPart6.sql diff --git a/sqlJoinsPart6.sql b/sqlJoinsPart6.sql new file mode 100644 index 0000000..a792674 --- /dev/null +++ b/sqlJoinsPart6.sql @@ -0,0 +1,8 @@ +/*Part 6 +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 EXTRACT(MONTH FROM paymentDate) AS Month, EXTRACT(YEAR FROM paymentDate) Year, FORMAT(SUM(amount), 2) AS 'Payments Received' +FROM payments +GROUP BY Month, YEAR