Tut 04
Tut 04
Instruction: In order to complete this tutorial, kindly execute the script and import the data from the
respective csv files. The script and the csv files can be obtained via eLearn@USM.
Two tables BOOKS_IN_KL and BOOKS_IN_PEN are created in a database to store book information
at two difference locations, one in Kuala Lumpur and one in Penang. Based on Figure 1 and Figure 2,
answer the following questions (Questions 1 – 7). You must use the relational set operators (e.g.
UNION, INTERSECT or MINUS) in your SQL commands, wherever applicable.
Question 2:
The management would like to know the total number of books located at both locations (duplicates
are allowed). Your SQL statement must produce a display as follows:
Question 3:
The management would like to know the statistical information of cost price of all the distinct books
located at both locations. These include maximum, minimum, average, standard deviation and variance
of the cost price. Your SQL statement must produce a display as follows. Please take note that the
values for average, standard deviation and variance must be rounded to 4 decimal places.
Question 4:
The management would like to get a list which shows the common books in both locations. All columns
must be included in the display list.
Question 5:
The management would like to get a list which shows the books at Kuala Lumpur branch but not
available at the Penang branch. All columns must be included in the display list.
Question 6:
The management would like to get a list which shows the books at Penang branch but not available at
the Kuala Lumpur branch. All columns must be included in the display list.
Question 7:
Create a trigger which does the following: whenever a record in the BOOKS_IN_KL table is updated or
a new record is inserted, the RET_PRICE will be auto computed as 5% more than the cost price. For
instance, a book with cost price of $10.00 is inserted; the RET_PRICE of that book would be $10.50.
Question 9:
By running the following SQL command,
SELECT * FROM JOB, EMPLOYEE;
similar results as of what have been produced by the SQL command in Question 8 can be generated.
[TRUE/FALSE]
Question 10:
Produce the output based on the following SQL command.
SELECT JOB_CODE, JOB_DESCRIPTION, EMP_LNAME
FROM JOB NATURAL JOIN EMPLOYEE
ORDER BY EMP_LNAME;
Question 11:
Produce the output based on the following SQL command.
SELECT JOB_CODE, JOB_DESCRIPTION, EMP_LNAME
FROM JOB JOIN EMPLOYEE USING(JOB_CODE)
ORDER BY EMP_LNAME;
Question 12:
Produce the output based on the following SQL command.
SELECT JOB_CODE, EMP_LNAME
FROM JOB LEFT JOIN EMPLOYEE USING(JOB_CODE)
ORDER BY EMP_LNAME;
Question 13:
Produce the output based on the following SQL command.
SELECT JOB.JOB_CODE, EMP_LNAME
FROM JOB LEFT JOIN EMPLOYEE ON JOB.JOB_CODE = EMPLOYEE.JOB_CODE
ORDER BY EMP_LNAME;
Question 14:
Produce a list of jobs from the JOB table where the JOB_CHG_HOUR is lesser than the overall
average of the JOB_CHG_HOUR. The anticipated output is shown as follows:
The first column displays the last name in all capital letters. The third column displays the first name
in all lowercase letters. The second and the fourth columns display the size of the last name and the
first name respectively. The fifth column displays the first three characters of the first name.
Question 16:
Create a stored procedure which does the following: increase the JOB_CHG_HOUR in the JOB table
to 10% of the original value for Programmer, Systems Analyst and Database Designer. Execute the
stored procedure.