Tutorial 4
Tutorial 4
127133
1. The management would like to have a list of books located at both locations
without the duplicates. Attributes which have to be shown in the list are ISBN,
title, category and cost. How many records will be in the list?
There are 11 records in the list.
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:
SELECT COUNT(ISBN) AS TOTAL FROM
(
SELECT ISBN, TITLE, CATEGORY, COST FROM BOOKS_IN_KL
UNION
SELECT ISBN, TITLE, CATEGORY, COST FROM BOOKS_IN_PEN
)
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.
SELECT MAX(COST) AS MAX_COST,
MIN(COST) AS MIN_COST,
ROUND(AVG(COST),4) AS AVD_COST,
ROUND(VARIANCE(COST),4) AS VARIANCE_COST,
ROUND(STDDEV(COST),4) AS STDDEC_COST
FROM
(
SELECT ISBN, COST FROM BOOKS_IN_KL
UNION
SELECT ISBN, COST FROM BOOKS_IN_PEN
)
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.
SELECT * FROM BOOKS_IN_KL
INTERSECT
SELECT * FROM BOOKS_IN_PEN
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.
SELECT * FROM BOOKS_IN_KL
MINUS
SELECT * FROM BOOKS_IN_PEN
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.
8. How many rows will be created when the following SQL command is
executed?
SELECT * FROM JOB CROSS JOIN EMPLOYEE;
198 records will be in the list.
9.
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;
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
SELECT JOB_CODE, JOB_DESCRIPTION, JOB_CHG_HOUR
FROM JOB
WHERE JOB_CHG_HOUR < (SELECT AVG(JOB_CHG_HOUR) FROM JOB)
15.Produce a list of employees from the EMPLOYEE table with the following
display:
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.
SELECT UPPER (EMP_LNAME) AS L_NAME , LENGTH (EMP_LNAME) AS
LNAME_SIZE , LOWER (EMP_FNAME) AS F_NAME , LENGTH (EMP_FNAME) AS
FNAME_SIZE , SUBSTR(EMP_FNAME, 1, 3) AS FNAME_PREFIX FROM
EMPLOYEE;
BEGIN
INCREASE_JOB_CHG_HOUR;
END;