diff --git a/part1.txt b/part1.txt new file mode 100644 index 0000000..1da0aa8 --- /dev/null +++ b/part1.txt @@ -0,0 +1,5 @@ +-- PART 1 +SELECT c.customerName AS "Customer Name", CONCAT(e.lastName, ', ', e.firstName) AS "Sales Rep" +FROM customers c JOIN employees e +ON c.salesRepEmployeeNumber=e.employeeNumber +ORDER BY c.customerName; \ No newline at end of file diff --git a/part2.txt b/part2.txt new file mode 100644 index 0000000..f2187e8 --- /dev/null +++ b/part2.txt @@ -0,0 +1,5 @@ +-- PART 2 +SELECT p.productName AS "Product Name", o.quantityOrdered AS "Total # Ordered", o.quantityOrdered * o.priceEach AS "Total Sale" +FROM products p JOIN orderdetails o +ON p.productCode = o.productCode +ORDER BY o.quantityOrdered * o.priceEach DESC; \ No newline at end of file diff --git a/part3.txt b/part3.txt new file mode 100644 index 0000000..1d9fb55 --- /dev/null +++ b/part3.txt @@ -0,0 +1,5 @@ +-- PART 3 +SELECT status AS "Order Status", COUNT(status) AS "# Orders" +FROM orders +GROUP BY status +ORDER BY status; \ No newline at end of file diff --git a/part4.txt b/part4.txt new file mode 100644 index 0000000..9f2c8fa --- /dev/null +++ b/part4.txt @@ -0,0 +1,6 @@ +--PART 4 +SELECT p.productLine AS "Product Line", SUM(o.quantityOrdered) AS "# Sold" +FROM products p JOIN orderDetails o +ON p.productCode=o.productCode +GROUP BY p.productLine +ORDER BY o.quantityOrdered DESC; \ No newline at end of file diff --git a/part5.txt b/part5.txt new file mode 100644 index 0000000..1919c5c --- /dev/null +++ b/part5.txt @@ -0,0 +1,12 @@ +-- PART 5 +SELECT CONCAT (e.lastName, ", ", e.firstName) AS 'Sales Rep', COUNT(o.orderNumber) AS '# Orders', IFNULL((od.quantityOrdered*od.priceEach), '0.00') AS 'Total Sales' +FROM employees e LEFT JOIN customers c +ON e.employeeNumber=c.salesRepEmployeeNumber +LEFT JOIN +orders AS o +ON o.customerNumber=c.customerNumber +LEFT JOIN +orderdetails AS od +ON o.orderNumber=od.orderNumber +GROUP BY CONCAT (e.lastName, ", ", e.firstName) +ORDER BY (od.quantityOrdered*od.priceEach) DESC; \ No newline at end of file diff --git a/part6.txt b/part6.txt new file mode 100644 index 0000000..fada8b9 --- /dev/null +++ b/part6.txt @@ -0,0 +1,5 @@ +-- PART 6 +SELECT MONTHNAME(paymentDate) AS 'Month', REPLACE(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 diff --git a/sqlJoins.txt b/sqlJoins.txt new file mode 100644 index 0000000..f4f0ee5 --- /dev/null +++ b/sqlJoins.txt @@ -0,0 +1,67 @@ +-- PART 1 +SELECT c.customerName AS "Customer Name", CONCAT(e.lastName, ', ', e.firstName) AS "Sales Rep" +FROM customers c JOIN employees e +ON c.salesRepEmployeeNumber=e.employeeNumber +ORDER BY c.customerName; + +-- PART 2 +SELECT p.productName AS "Product Name", o.quantityOrdered AS "Total # Ordered", o.quantityOrdered * o.priceEach AS "Total Sale" +FROM products p JOIN orderdetails o +ON p.productCode = o.productCode +ORDER BY o.quantityOrdered * o.priceEach DESC; + +-- PART 3 +SELECT status AS "Order Status", COUNT(status) AS "# Orders" +FROM orders +GROUP BY status +ORDER BY status; + + +--PART 4 +SELECT p.productLine AS "Product Line", SUM(o.quantityOrdered) AS "# Sold" +FROM products p JOIN orderDetails o +ON p.productCode=o.productCode +GROUP BY p.productLine +ORDER BY o.quantityOrdered DESC; + +-- PART 5 +SELECT CONCAT (e.lastName, ", ", e.firstName) AS 'Sales Rep', COUNT(o.orderNumber) AS '# Orders', IFNULL((od.quantityOrdered*od.priceEach), '0.00') AS 'Total Sales' +FROM employees e LEFT JOIN customers c +ON e.employeeNumber=c.salesRepEmployeeNumber +LEFT JOIN +orders AS o +ON o.customerNumber=c.customerNumber +LEFT JOIN +orderdetails AS od +ON o.orderNumber=od.orderNumber +GROUP BY CONCAT (e.lastName, ", ", e.firstName) +ORDER BY (od.quantityOrdered*od.priceEach) DESC; + + +-- PART 6 +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; + + + + + + + + + + + + + + + + + + + + + +