LAB EXAM - Database Systems Duration: 60 minutes Import database classicmodels by executing mysqlsampledatabase.sql script that you can find on LMS. The database that we will use for this lab exam is called classicmodels. The classicmodels database is a retailer of scale models of classic cars database. It contains typical business data such as customers, products, sales orders, sales order line items, etc. This database schema consists of the following tables: - Customers: stores customer’s data. Products: stores a list of scale model cars. Orders: stores sales orders placed by customers. OrderDetails: stores sales order line items for each sales order. Payments: stores payments made by customers based on their accounts. Employees: stores all employee information as well as the organization structure such as who reports to whom. - Offices: stores sales office data. ------------------------------------------------------------------------------------------------------------------------------1. (25%) Write SQL query that will, for every customer and every product, return a total quantity of ordered products (total_quantity) together with the customer name and product name. Order result set by total_quantity in descending order. The query will return 2532 rows. Hint: Add LIMIT 3000 to your query in order to verify that the correct number of rows is returned. Tables needed: customers, orders, orderdetails, products ------------------------------------------------------------------------------------------------------------------------------2. (35%) Write a SQL query that will return the total amount of payments for every employee in every country and every city where the payment date is greater than 2004-12-15. The query should also return a comma-separated list of payment check numbers (use GROUP_CONCAT function). Order result set in descending order by country column. The query will return 14 rows. Tables needed: offices, employees, customers, payments ------------------------------------------------------------------------------------------------------------------------------3. (40%) Write MySQL function (name of the function should be customer_level) that will receive customer number as a parameter. The function will get the total amount of payments for that customer and check in which category customer belongs to and return the output as follows: Conditions Output customer_sales > 50000 AND customer_sales <= 100000 'GOOD' customer_sales > 100000 AND customer_sales <= 150000 'BETTER' customer_sales > 150000 ‘BEST’ None of the conditions are satisfied ‘WORST’ Tables needed: customers, payments In order to check if the function is working properly invoke the following commands and output should be as written next to the select statement SELECT customer_level(114) - o utput should be ‘BEST’ SELECT customer_level(103) - o utput should be ‘WORST’ Hint: F unction skeleton DELIMITER $$ CREATE FUNCTION function_name( param1, param2,… ) RETURNS datatype [NOT] DETERMINISTIC BEGIN -- statements END $$ DELIMITER ;