Juicd (part 2)

The final part of the project is to pull together all the different aspects of SQL that we have learned so far and apply them to a made-up database for Juicd. These will primarily be marked on correctness - whether they do the right thing or not - but I may check some of the code if it is particularly slow or similar.

The database schema is available in the file juicd.sql and a sample dataset is in data.txt. You should load the schema and the data into your own server, and then use MySQL Workbench to get the structure diagram for the schema.

A faster way to insert the data is to download juicdump3.sql and upload this file to your server. NOTE: This is the new dataset with data for about six months.

Post to help1402 for guidance if there is any ambiguity in how to interpret the questions (but please do not post actual code unless you have okayed it with me first).

The remaining questions will be added to this file in the next few days.

Basic queries (6 marks)

Place all 10 queries into a single text file with the name basic.sql so that they can be automatically run by a script.

These queries are all single SQL queries that require nothing more than joins and elementary use of the aggregate functions with GROUP BY. All students should be able to write queries at this level for the exam.

More complex queries (8 marks)

These queries are more complex than the basic SQL queries and may involve more exotic join conditions, such as outer joins, subqueries and simple stored procedures or functions.

Place all queries and function definitions into a single text file with the name complex.sql so that they can be automatically run by a script.

A stored function is similar to a stored procedure, except that it returns a value that can be used in a SQL statement just like the other SQL functions. See this Stored Function Tutorial for some more details on how to declare the function and return the values (ignore the DETERMINISTIC keyword).

mysql> select juiceCupCost(10);
+------------------+
| juiceCupCost(10) |
+------------------+
|              340 |
+------------------+

Additional functionality (6 marks)

Place all queries and view/procedure definitions into a single text file with the name additional.sql so that they can be automatically run by a script.

Written with StackEdit.