Download - 04 laboratory exercise 1
F0004
04 Laboratory Exercise 1 *Property of STI Page 1 of 4
Laboratory Exercise Working With OLAP Operations
Objectives
At the end of this exercise, the students are expected to:
Apply the CUBE operation
Apply the GROUPING SETS operation
Apply ROLLUP operation
Computer Terminal
Software installed on the terminal: Sybase SQL Anywhere 9 Opening documents/reading – i.e. MS
Word, Acrobat Reader, etc.
Printer and Paper (as necessary)
Activity 1 Creating and Populating the Table
1. Open Sybase Central. 2. Create a new database and name it "ADDBASE_LAB4". 3. Using the Sybase Central, create the table Employee. The table structure is described
below:
ID VARCHAR(4) NOT NULL,
First_Name VARCHAR(10),
Last_Name VARCHAR(10),
Start_Date DATE,
End_Date DATE,
Salary Integer,
City VARCHAR(10),
Description VARCHAR(15)
4. Using the Interactive SQL, populate the Employee table. The sample values are listed below.
ID FIRST_NAME LAST_NAME START_DATE END_DATE SALARY CITY DESCRIPTION
01 Erika Maminta 25-JUL-96 25-JU06 1234.56 Makati Programmer
02 Alison Abalos 21-MAR-76 21-FEB-86 6661.78 Makati Tester
03 James Bartolome 12-DEC-78 15-MAR-90 6544.78 QC Tester
04 Celia Lopez 24-OCT-82 21-APR-99 2344.78 QC Manager
05 Robert San Miguel 15-JAN-84 08-AUG-98 2334.78 Makati Tester
06 Linda Liu 30-JUL-87 04-JAN-96 4322.78 Manila Tester
07 David Dolde 31-DEC-90 12-FEB-98 7897.78 Manila Manager
08 Lebron James 17-SEP-96 15-APR-02 1232.78 QC Tester
Activity 2 Using the ROLLUP Operation
1. Interactive SQL, type the code below and execute.
SELECT
city, description, SUM(salary),
RANK() OVER (ORDER BY SUM(salary) DESC) AS rank
FROM employee
F0004
04 Laboratory Exercise 1 *Property of STI Page 2 of 4
GROUP BY ROLLUP(city)
ORDER BY city, description;
2. List the output and explain the output of the operation.
Activity 3 Using the CUBE Operation
1. Using the Interactive SQL, type the code below.
SELECT city, SUM(salary)
FROM employee
GROUP BY CUBE(city);
2. List the output and explain the output of the operation.
3. Use CUBE and RANK() to get all rankings of salaries by city and description. You may refer to
Step 1 of ROLLUP Operation. 4. List the output and explain the output of the operation.
F0004
04 Laboratory Exercise 1 *Property of STI Page 3 of 4
5. Modify Step 1 to include the description column in the CUBE function. 6. List the output and explain the output of the operation.
Activity 4 Using the GROUPING SETS Operation
1. Using the Interactive SQL, type the code below.
SELECT city, description, SUM(salary)
FROM employee
GROUP BY GROUPING SETS(city, description);
2. List the output and explain the output of the operation.