Assignment 1 Solution

$29.99 $18.99

Q1[total 10: (-1 point for every mistake)]​Consider a table ​Payment​.It has the following fields: payment_id​,​customer_id​,​staff_id​,​amount​,​payment_date​.The ​payment_id​field identifies the tuple. The ​customer_id​and ​staff_id​fields are foreign keys to the ​Customer​and ​Staff ​table, respectively. It tells us which customer made the payment and which staff member processed the payment. The last field denotes the date when the payment…

You’ll get a: . zip file solution

 

 
Categorys:
Tags:

Description

Rate this product

Q1[total 10: (-1 point for every mistake)]Consider a table Payment.It has the following fields: payment_id,customer_id,staff_id,amount,payment_date.The payment_idfield identifies the tuple. The customer_idand staff_idfields are foreign keys to the Customerand Staff table, respectively. It tells us which customer made the payment and which staff member processed the payment. The last field denotes the date when the payment was made. Obviously, a customer can make several payments on the same date. Complete the following picture by putting checkmarks where appropriate. The picture is for the Paymenttable. For example, there is a checkmark for payment_idand Primary keybecause payment_idis the primary key for the Paymenttable.

Primary key

Candidate Key

Super key

payment_id

customer_id

payment_id,customer_id

amount, payment_date

payment_id,staff_id

For the following questions, download the assignment1.zip file from Polylearn.

Q2[total 20: 5 per table]Suppose you want to record information about soccer players, their teams, the games where they played, and events (such as ‘a goal scored’) in each game. Create a Playertable that stores information about the soccer players. Create a Gametable that stores information about the games. Every game is between two teams. Create a Eventtable recording all events occurred in each game. Create a Teamtable that stores information about all the teams. Every soccer player belongs to exactly one team (i.e., add a team_idfield to the Playertable).

Submit the create tablestatements for the four tables. Include primary key and foreign key constraints.

Q3[20: 10 per table]Create INSERT statements to insert all the data given in supplied text files containing json data to the tables (statements for two of the tables are given. Your task it to crate statements for the remaining two tables). It is recommended that you use Python rather than Java. You need to create a file containing insert statements just like the provided teams.sql and players.sql files.

Q4[total 25] Create the tables in MySQL and populate them with the data using the insert statements including the ones you created. You should be able to insert all the data into the 4 tables without an error or warning. If you get an error or warning, that means that your table schema needs to be changed.

You can execute sql statements in a file from mysql shell with the following command: source [filename];

Replace the [filename] with a file name containing sql statements. You might need to prepend the path to the file to the filename if the file is not in your current directory on your machine.

Q5[total 25: 5 per query]write, test, and submit the SQL for the following queries. Add the distinct keyword if you want to eliminate duplicates.

  1. Print the names of soccer players that have scored a hat-trick (3 or more goals per game).

  1. Print the names of teams that have one or more players that have scored a hat-trick.

  1. Print the names of teams that have scored more than 3 goals in a single game.

  1. Suppose that a team that won the most games win the championship. Write a query to find out which team won the most games. i.e. find the champion team.

  1. Write a query to list all the teams that beat the champion team.

Zip your files containing the answer to Q1 and sql statements and submit it to polylearn. Do not forget to include your name in the files.