Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions part1.txt
Original file line number Diff line number Diff line change
@@ -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;
5 changes: 5 additions & 0 deletions part2.txt
Original file line number Diff line number Diff line change
@@ -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;
5 changes: 5 additions & 0 deletions part3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- PART 3
SELECT status AS "Order Status", COUNT(status) AS "# Orders"
FROM orders
GROUP BY status
ORDER BY status;
6 changes: 6 additions & 0 deletions part4.txt
Original file line number Diff line number Diff line change
@@ -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;
12 changes: 12 additions & 0 deletions part5.txt
Original file line number Diff line number Diff line change
@@ -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;
5 changes: 5 additions & 0 deletions part6.txt
Original file line number Diff line number Diff line change
@@ -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;
67 changes: 67 additions & 0 deletions sqlJoins.txt
Original file line number Diff line number Diff line change
@@ -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;