Assignment 2

Posted ak918xp

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Assignment 2相关的知识,希望对你有一定的参考价值。

1.With reference to the sample HR Schema in Oracle Express 18c docker container, write the SQL query statements AND capture a screenshot of the output of your queries in SQL Developer.

a)Show the EMPLOYEE_ID, FIRST_NAME, LAST_NAME and DEPARTMENT_NAME of the employees who are the manager of at least one other employees in the department. The result should be sorted in ascending EMPLOYEE_ID.

select employees.employee_id,employees.first_name,employees.last_name,departments.department_name
from employees
inner join departments
on employees.department_id=departments.department_id
where employees.employee_id in(
select a.employee_id
from employees a,employees b
where a.employee_id=b.manager_id
group by a.employee_id
)
order by employees.employee_id asc
;

   技术图片 技术图片

技术图片

b)For each department, show the city where the department is located and the number of employees in the department, sorted by decreasing number of employees in the department followed by ascending department name (if two departments have the same number of employees).

select department_name department, locations.city city,count(employees.department_id) count
from departments
join employees 
on departments.department_id=employees.department_id
join locations 
on locations.location_id=departments.location_id 
group by department_name,locations.city
order by count desc, departments.department_name asc;

技术图片

 c)For each department with more than 3 employees whose salary is higher than the average salary of the company, show the number the number of employees whose salary is higher than the average salary of the company.

with tmp(avg_sal,department_id)
as (select avg(salary) avg_sal,department_id from employees group by department_id)

select department_id,count(employee_id)
from employees natural join tmp
where salary>avg_sal
group by department_id
having count(employee_id)>3

技术图片

d) For each department, show the first name and last name of the employee whose salary is higher than all employees in that department. The result should be ordered by ascending department name. You should ignore those departments in which none of the employee’s salary is known.

select department_name as Department,first_name as First_Name,last_name as Last_Name ,salary from employees emp 
join departments dept 
on emp.department_id = dept.department_id 
where (emp.department_id ,emp.salary) 
in (select department_id ,max(Salary) as Salary  
from employees 
group by department_id
)
order by department_name asc
;

技术图片

 

2.Implement the following requirements in the PDB XEPDB1 in Oracle docker container.

技术图片

? Create local users Tim, Joe and Mavis

技术图片

? Tim and Joe are assigned the programmer role

技术图片

? Mavis is assigned the supervisor role

技术图片

? Users assigned a local programmer role should be able to establish a connection to Oracle Database Server, create tables in his/her own user account select/updating/inserting/deleting from the table created by him/her, and dropping the tables created by him/her.

技术图片

? Users assigned the supervisor role get all the permissions assigned to programmer role as well as the privilege to execute select query on all the tables in the pluggable database.

 技术图片

 缺少授权查询的图

a) Provide the SQL statements to create the users/roles and grant appropriate permission.
b) After executing the various SQL statements in part (a), what SQL statements should we use to check whether the roles/permissions are created/assigned appropriately? Discuss the purpose of the SQL statements and the output of the corresponding statements in SQL Developer.

查看用户或者角色系统权限

select * from dba_sys_privs;
select * from user_sys_privs;

查看角色包含的权限

select * from role_sys_privs

 



以上是关于Assignment 2的主要内容,如果未能解决你的问题,请参考以下文章

cs231n Assignment1相关代码

COMP9319 2019T2 Assignment 2

Assignment 2—Simulation Report LATEX

python 数据争夺ASsignment 2第2部分

CSI3131 Assignment 2 Winter 2019

必须使用解构道具分配(react/destructuring-assignment)