Presentation is loading. Please wait.

Presentation is loading. Please wait.

SQL and Data Modeling Jeopardy

Similar presentations


Presentation on theme: "SQL and Data Modeling Jeopardy"— Presentation transcript:

1 SQL and Data Modeling Jeopardy
MIST 4610 Summer 2017

2 Game Format STEP 1 GAME FORMAT
Get with your group project team. You will work together when answering the jeopardy questions GAME FORMAT Each query and data model have two levels of difficulty Easy and hard 10 queries (including 2 warm-ups) Each easy query is worth 1 point (warm-ups do not count) Each hard query is worth 2 points (warm-ups do not count) 3 data models (no warm-ups) Easy data model is worth 1 point Hard data model is worth 2 points Hard-ish data model is worth 3 points

3 Each member of the winning team will get …
Game Format GAME FORMAT SCORING 4 easy and 4 hard queries (total of 12 points) 1 easy, 1 medium, and 1 kind of hard data model (total of 6 points) WINNER Each member of the winning team will get … BRAGGING RIGHTS! RUNNER UP gets “nada,” sorry!

4 Game Rules RULES When you are ready to answer raise your hand. Whoever does it first gets to answer the question first. If the answer is incorrect the group loses points (e.g., -1 if you miss the first easy query) Every group will have a maximum of 10 minutes per query and 15 minutes per data model. If nobody gets the right answer nobody will receive a point

5 SQL and Data Modeling Jeopardy
WARM-UP

6 SQL – Category “Warming Up”
How many sales managers report to the sales VP? SELECT COUNT(*) FROM Employees boss, Employees reports WHERE boss.employeeNumber = reports.reportsTo AND boss.jobTitle REGEXP 'VP Sales' AND reports.jobTitle REGEXP 'Sales Manager';

7 SQL – Category “Warming Up”
Report the product name and total buy price for each product shipped on November Sort results by shipped date and product name. SELECT productName, shippedDate, sum(buyPrice) FROM Products, OrderDetails, Orders WHERE Products.productCode = OrderDetails.productCode AND Orders.orderNumber = OrderDetails.orderNumber AND YEAR(shippedDate) = 2003 AND MONTH(shippedDate) = 11 GROUP BY productName ORDER BY shippedDate, productName;

8 SQL and Data Modeling Jeopardy
STARTS NOW…

9 SQL 1 – Category “Easy” List the required date and order number of all orders shipped in November Sort by required date and order number. SELECT requiredDate, orderNumber FROM Orders WHERE MONTH(shippedDate) = 11 AND YEAR(shippedDate) = 2003 ORDER BY requiredDate, orderNumber

10 SQL 2 – Category “Easy” List the name and price of each cancelled Porsche product. Sort by highest price to lowest. Format to two decimals. SELECT productName, FORMAT(priceEach,2) AS 'Price' FROM OrderDetails, Orders, Products WHERE OrderDetails.orderNumber = Orders.orderNumber AND OrderDetails.productCode = Products.productCode AND status = 'Cancelled' AND productName REGEXP 'Porsche' ORDER BY priceEach DESC;

11 SQL 3 – Category “Hard” Find all orders where it took more than a year for the customer to pay for the order. SELECT orderNumber, datediff(paymentDate,orderDate) as DaysTakenToPay, amount as AmountInDollars FROM Payments,Customers,Orders WHERE Payments.customerNumber = Customers.customerNumber AND Customers.customerNumber = Orders.customerNumber AND datediff(paymentDate,orderDate) > 365;

12 SQL 4 – Category “Hard” Report the total revenue for each sales rep who has completed an order. Format results to show two decimal places. Sort and group results by employee's last name. SELECT lastName, ROUND(SUM(quantityOrdered*priceEach),2) AS 'Total Revenue’ FROM OrderDetails, Orders, Customers, EmployeesWHERE OrderDetails.orderNumber = Orders.orderNumberAND Orders.customerNumber = Customers.customerNumberAND Customers.salesRepEmployeeNumber = Employees.employeeNumberAND jobTitle = 'Sales Rep'GROUP BY lastNameORDER BY lastName;

13 SQL 5 – Category “Easy” Which country/countries has/have more than 2 offices? SELECT country, COUNT(*) FROM Offices GROUP BY country HAVING COUNT(*) > 2

14 SQL 6 – Category “Easy” List the and phone extension for all employees working in Australia. Sort results by . SELECT , extension FROM Offices, Employees WHERE Offices.officeCode = Employees.officeCode AND country = 'Australia' ORDER BY

15 SQL 7 – Category “Hard” Are there any products that have appeared in all orders? SELECT productCode, productName FROM products WHERE NOT EXISTS                         (SELECT * FROM orders                                WHERE NOT EXISTS                                            (SELECT * FROM orderdetails                   WHERE orderdetails.Productcode = products.productCode                   AND orderdetails.ordernumber = orders.ordernumber));

16 SQL 8 – Category “Hard” Find the customer name and total credit limit (only if higher than 90000) for all customer accounts that are controlled by William Patterson through the sales representative Andy Fixter. Organize the data by the customer name in alphabetical order. Finally, make sure the columns are labeled for ease of reading by the Marketing Director. SELECT customerName, SUM(creditLimit) AS 'Total Credit Limit', emp.lastName AS 'Sales Rep Last Name', emp.firstName AS 'Sales Rep First Name', boss.lastName 'Boss Last Name', boss.firstName 'Boss First Name' FROM Customers, Employees emp, Employees boss WHERE Customers.salesRepEmployeeNumber = Employees.employeeNumber AND emp.reportsTo = boss.employeeNumber AND boss.firstName = 'William' AND boss.lastName = 'Patterson' AND emp.firstName = 'Andy' AND emp.lastName = 'Fixter' GROUP BY boss.lastName, customerName HAVING SUM(creditLimit) > 90000 ORDER BY customerName;

17 SQL and Data Modeling Jeopardy
BREAK TIME

18 Data Modeling – Category “Easy”
A dairy farmer, who is also a part-time cartoonist, has several herds of cows. He has assigned each cow to a particular herd. In each herd, the farmer has one cow that is his favorite--often that cow is featured in a cartoon. Draw a data model to represent this scenario.

19 Data Modeling – Category “Medium”
A consulting company has assigned each of its employees to a specialist group (e.g., database management). Each specialist group has a team leader. When employees join the company, they are assigned a mentor for the first year. One person might mentor several employees, but an employee has at most one mentor. Draw a data model to represent this scenario.

20 Data Modeling – Category “Hard-ish”
The National Office of Academic Conferences (N. O.A.C.) wants to keep track of the conferences attended by university researchers. It gives you the following information: A university is identified by its name and located in a particular city. A university has many researchers, each of whom can only be associated with only one university. A researcher is identified by an identification number, and has a name, phone, and address. A researcher can attend many conferences. A conference is identified by an identification number; it also has a name, a location, and a date. For each conference, a researcher may or may not present a scientific research paper. For each conference, one university is in charge of its logistics, while another university is in charge of its marketing. A university can be involved in either role with any conference.

21 Data Modeling – Category “Hard-ish”


Download ppt "SQL and Data Modeling Jeopardy"

Similar presentations


Ads by Google