diff --git a/Part1.sql b/Part1.sql new file mode 100644 index 0000000..fdc40a5 --- /dev/null +++ b/Part1.sql @@ -0,0 +1,8 @@ +SELECT * FROM customers; + +SELECT * FROM employees; + + +SELECT cus.customerName AS 'Customer Name',CONCAT(emp.firstName,' ',emp.lastName) AS 'Sales Rep' +FROM customers cus JOIN employees emp ON cus.salesRepEmployeeNumber=emp.employeeNumber +ORDER BY cus.customerName ASC; diff --git a/Part2.sql b/Part2.sql new file mode 100644 index 0000000..05799b7 --- /dev/null +++ b/Part2.sql @@ -0,0 +1,11 @@ +SELECT * from products; + +SELECT * from orderdetails; + + +SELECT prod.productName 'Product Name', orderD.quantityOrdered 'Total # Order', (orderD.quantityOrdered * orderD.priceEach) AS 'Total Sale' +FROM products prod +JOIN orderdetails orderD +ON prod.productCode=orderD.productCode +GROUP BY prod.productName +ORDER BY (orderD.quantityOrdered * orderD.priceEach) desc; \ No newline at end of file diff --git a/Part3.sql b/Part3.sql new file mode 100644 index 0000000..d5dfbcd --- /dev/null +++ b/Part3.sql @@ -0,0 +1,6 @@ +SELECT * FROM orders; + +SELECT STATUS 'Order Status', COUNT(STATUS) '# Orders' +FROM orders +GROUP BY STATUS +ORDER BY STATUS asc; \ No newline at end of file diff --git a/Part4.sql b/Part4.sql new file mode 100644 index 0000000..effff3d --- /dev/null +++ b/Part4.sql @@ -0,0 +1,9 @@ +SELECT * FROM products; + +SELECT * FROM orderdetails; + +SELECT prod.productLine 'Product Line', count(orderD.quantityOrdered) '# Sold' +FROM products prod JOIN orderdetails orderD +ON prod.productCode = orderD.productCode +GROUP BY prod.productLine +ORDER BY count(orderD.quantityOrdered) desc ; \ No newline at end of file diff --git a/Part5.sql b/Part5.sql new file mode 100644 index 0000000..2beb400 --- /dev/null +++ b/Part5.sql @@ -0,0 +1,15 @@ + + + +SELECT CONCAT(emp.lastName,' ',emp.firstName) AS 'Sales_Rep', +COUNT(orderD.quantityOrdered) AS '#_Orders', +IFNULL((sum(orderD.quantityOrdered * orderD.priceEach)), 0) AS 'Total_Sales' +FROM employees emp +left JOIN customers cus ON emp.employeeNumber=cus.salesRepEmployeeNumber +left JOIN orders orde ON cus.customerNumber=orde.customerNumber +left JOIN orderDetails orderD on orde.orderNumber=orderD.orderNumber +WHERE emp.jobTitle='Sales Rep' +GROUP BY Sales_Rep +ORDER BY Total_Sales DESC ; + + diff --git a/Part6.sql b/Part6.sql new file mode 100644 index 0000000..4e4375f --- /dev/null +++ b/Part6.sql @@ -0,0 +1,6 @@ + + +SELECT MonthName(paymentDate) 'Month',Year(paymentDate) 'Year', sum(amount) 'Payment_received' +FROM payments +GROUP BY MONTH ; +