-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathL06_159100171_HONG.sql
More file actions
116 lines (87 loc) · 3.37 KB
/
L06_159100171_HONG.sql
File metadata and controls
116 lines (87 loc) · 3.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
-- ***********************
-- Name: Youngeun Hong
-- ID: 159100171
-- Date: 29 JUNE 2019
-- Purpose: Lab 6 DBS301
-- ***********************
-- Question 1 –
-- SET AUTOCOMMIT ON (do this each time you log on) so any updates, deletes and inserts
-- are automatically committed before you exit from Oracle.
-- Q1 SOLUTION --
SET AUTOCOMMIT ON
-- Question 2 –
-- Create an INSERT statement to do this. Add yourself as an employee with a NULL salary,
-- 0.21 commission_pct, in department 90, and Manager 100. You started TODAY.
-- Q2 SOLUTION --
INSERT INTO EMPLOYEES
(EMPLOYEE_ID, FIRST_NAME, LAST_NAME, EMAIL, HIRE_DATE, JOB_ID,
COMMISSION_PCT, MANAGER_ID, DEPARTMENT_ID)
VALUES (207, 'YOUNGEUN', 'HONG', 'YHONG38@MYSENECA.CA', '28-JUN-19',
'AD_PRES', 0.21, 100, 90);
-- Question 3 –
-- Create an Update statement to:
-- Change the salary of the employees with a last name of Matos and Whalen to be 2500.
-- Q3 SOLUTION --
UPDATE EMPLOYEES
SET SALARY = 2500
WHERE LAST_NAME IN ('Matos', 'Whalen');
-- Question 4 –
-- Display the last names of all employees who are in the same department
-- as the employee named Abel.
-- Q4 SOLUTION --
SELECT LAST_NAME
FROM EMPLOYEES
WHERE DEPARTMENT_ID = (SELECT DEPARTMENT_ID FROM EMPLOYEES
WHERE LAST_NAME = 'Abel');
-- Question 5 –
-- Display the last name of the lowest paid employee(s)
-- Q5 SOLUTION --
SELECT LAST_NAME
FROM EMPLOYEES
WHERE SALARY = (SELECT MIN(SALARY) FROM EMPLOYEES);
-- Question 6 –
-- Display the city that the lowest paid employee(s) are located in.
-- Q6 SOLUTION --
SELECT CITY
FROM EMPLOYEES E
JOIN DEPARTMENTS D ON (E.DEPARTMENT_ID = D.DEPARTMENT_ID)
JOIN LOCATIONS L ON (D.LOCATION_ID = L.LOCATION_ID)
WHERE SALARY = (SELECT MIN(SALARY) FROM EMPLOYEES);
-- Question 7–
-- Display the last name, department_id, and salary of the lowest paid employee(s) in each department.
-- Sort by Department_ID. (HINT: careful with department 60)
-- Q7 SOLUTION --
SELECT LAST_NAME, DEPARTMENT_ID, SALARY
FROM EMPLOYEES
WHERE (DEPARTMENT_ID, SALARY) IN (SELECT DEPARTMENT_ID, MIN(SALARY)
FROM EMPLOYEES GROUP BY DEPARTMENT_ID)
ORDER BY DEPARTMENT_ID;
-- Question 8 –
-- Display the last name of the lowest paid employee(s) in each city
-- Q8 SOLUTION --
SELECT LAST_NAME
FROM EMPLOYEES
JOIN DEPARTMENTS USING(DEPARTMENT_ID)
JOIN LOCATIONS USING(LOCATION_ID)
WHERE(CITY, SALARY) IN(SELECT CITY, MIN(SALARY)
FROM EMPLOYEES
JOIN DEPARTMENTS USING(DEPARTMENT_ID)
JOIN LOCATIONS USING(LOCATION_ID)
GROUP BY CITY);
-- Question 9–
-- Display last name and salary for all employees who earn less than the lowest salary in ANY department.
-- Sort the output by top salaries first and then by last name.
-- Q9 SOLUTION --
SELECT LAST_NAME, SALARY
FROM EMPLOYEES
WHERE SALARY < ANY(SELECT MIN(SALARY) FROM EMPLOYEES
GROUP BY DEPARTMENT_ID)
ORDER BY SALARY DESC, LAST_NAME;
-- Question 10 –
-- Display last name, job title and salary for all employees whose salary matches any of the salaries from the IT Department.
-- Do NOT use Join method. Sort the output by salary ascending first and then by last_name
-- Q10 SOLUTION --
SELECT LAST_NAME, JOB_ID, SALARY
FROM EMPLOYEES
WHERE SALARY IN (SELECT SALARY FROM EMPLOYEES WHERE DEPARTMENT_ID = 60)
ORDER BY SALARY, LAST_NAME;