You are on page 1of 6

Kyruss N.

Lopez BSIT 3-C SIA

I. Using the tables provided write a query based on the following criteria:

1. IT Support and IT Helpdesk have been merged due to cost cutting happened to the
company, which forced the company to make them one department which is IT Support.
Now the database must be change accordingly:
a. Write a query that makes the existing data of employees under IT Helpdesk be
updated to IT Support.
 UPDATE Employees
SET DEPARTMENT_ID = 210
WHERE DEPARTMENT_ID = 230;

b. Write a query that will delete the Department.


 DELETE FROM Departments
WHERE DEPARTMENT_ID = 230;

2. Due to this cost cut happened in the company several reports have been needed:
a. Write a query that will retrieve the complete name of the employee, contact number,
department name, and state province for each employee.
 SELECT E.first_name,E.last_name, E.phone_number,
D.department_name, L.state_province
FROM employees E
JOIN departments D
ON E.department_id = D.department_id
JOIN locations L
ON D.location_id = L.location_id;

b. Write a query that will retrieve the complete name of the employee, Salary, that
belong to the Finance department.
 SELECT first_name, last_name, salary
FROM employees
WHERE department_id = d.department_id
AND d.department_name = 'Finance';
c. Write a query that will display all the details of the employee that has a salary higher
than 12000.00.
 SELECT * FROM employees
WHERE salary > 12000.00;

d. List of all department names and their state province.


 SELECT D.department_name , L.state_province
FROM departments D
JOIN locations L
ON D.location_id = L.location_id;

3. A new department named Graphics has been formed and their office has been built
in 21246 Harumi Ofuisutawaz, City of Tokyo Japan under state province of Chuo-ku
with a postal code of 1046223.
a. Write a query that will insert a new record based from number three description on
Locations table.
 INSERT INTO Locations
(STREET_ADDRESS, POSTAL_CODE, CITY, STATE_PROVINCE,
COUNTRY_ID)
VALUES ('Harumi Ofuisutawaz', '1046223.', 'Tokyo', 'Japan', 'JP');

b. Since a new location is added and its Location ID is 3300 kindly write a query that will
add the Graphics department on the Departments table with the new location ID and
they are all under the supervision of Steven King.
 INSERT INTO Departments
(‘DEPARTMENT_NAME’)VALUES(‘GRAPHICS)
SELECT L. LOCATION_ID
FROM Locations L
WHERE L.LOCATION_ID = 1700;
4. Random request and updates that needs to be applied in the database:
a. Write a query that will add the following details of the newly hired employee.

 INSERT INTO Employees


(FIRST_NAME, LAST_NAME, EMAIL, PHONE_NUMBER, HIRE_DATE)
VALUES('Michael','Doe ','DOE', '515.123.4432','2021-01-17');

b. Write a query that will display all the employees who was hired from 2002 to 2006
sorted by from 2000 upwards.
 SELECT * FROM Employees
WHERE HIRE_DATE BETWEEN 2000 AND 2006
ORDER BY HIRE_DATE;

c. Write a query that will display all the Locations Details.


 SELECT * FROM locations;

d. Write a query that will display the first name, last name, department id and
department name, for all employees for departments 80 or 40.
 SELECT E.first_name , E.last_name ,
E.department_id , D.department_name
FROM employees E
JOIN departments D
ON E.department_id = D.department_id
AND E.department_id IN (80 , 40)
ORDER BY E.last_name;

e. Write a query that will display the first name of all employees including the first name
of their manager.
 SELECT E.first_name AS "Employee Name",
M.first_name AS "Manager"
FROM employees E
JOIN employees M
ON E.manager_id = M.employee_id;
II. Draw or write the expected output of the following queries:

1. SELECT EMPLOYEE_ID, LAST_NAME, FIRST_NAME, SALARY,


DEPARTMENT_ID FROM Employees WHERE SALARY <= 10000 ORDER BY
FIRST_NAME DESC;
EMPLOYEE_ID LAST_NAME FIRST_NAM SALARY DEPARTMENT_ID
E
180 Taylor Winston 3200.00 50
206 Gietz William 8300.00 110
171 Smith William 7400.00 80
195 Jones Vance 2800.00 50
106 Pataballa Valli 4800.00 60
141 Rajs Trenna 3500.00 50
190 Gates Timothy 2900.00 50
170 Fox Tayler 9600.00 80
132 Olson TJ 2100.00 50

2. SELECT * FROM Locations WHERE POSTAL_CODE = 445423;


 NO result found from Locations Table in POSTAL_CODE YOU WERE GIVEN
445423.

3. SELECT E.FIRST_NAME, E.LAST_NAME, E.SALARY


FROM Employees E
JOIN Employees S
ON E.SALARY < S.SALARY
AND S.EMPLOYEE_ID = 182;

FIRST_NAME LAST_NAME SALARY


James Landry 2400.00
Steven Markle 2200.00
TJ Olson 2100.00
Ki Gee 2400.00
Hazel Philtanker 2200.00

4. SELECT E.FIRST_NAME,E.LAST_NAME,
D.DEPARTMENT_NAME
FROM Employees E
JOIN Departments D
ON E.DEPARTMENT_ID = D.DEPARTMENT_ID;

FIRST_NAME LAST_NAME .DEPARTMENT_NAME


Steven King Executive
Neena Kochhar Executive
Lex De Haan Executive
Alexander Hunold IT
Bruce Ernst IT
David Austin IT
Valli Pataballa IT
Diana Lorentz IT
Nancy Greenberg Finance
Daniel Faviet Finance
John Chen Finance
Ismael Sciarra Finance

5. SELECT E.FIRST_NAME,E.LAST_NAME,
D.DEPARTMENT_NAME, L.CITY, L.STATE_PROVINCE
FROM Employees E
JOIN Departments D
ON E.DEPARTMENT_ID = D.DEPARTMENT_ID
JOIN Locations L
ON D.LOCATION_ID = L.LOCATION_ID;

FIRST_NAM LAST_NAM DEPARTMENT_NAM CITY STATE_PROVINC


E E E E
Steven King Executive Seattle Washington
Neena Kochhar Executive Seattle Washington
Lex De Haan Executive Seattle Washington
Alexander Hunold IT Southlak Texas
e
Bruce Ernst IT Southlak Texas
e
David Austin IT Southlak Texas
e
Valli Pataballa IT Southlak Texas
e
Diana Lorentz IT Southlak Texas
e

III. Write a single line query to display the following output:

 SELECT * FROM Locations;

You might also like