Vous êtes sur la page 1sur 19

Learning Oracle SQL Your precious replies and comments will be highly appreciated. Thanks.

[Note : If any queries or doubts, please post it in the comments in this blog]

The following tables represent data about employees, skills, projects, project teams. The columns, their description and some sample data is provided. (If value is blank, treat them as null)
Main Tables

Employee_Portfolio

emp_id Unique identifier

emp_name Name of employee

3251 Mark 4562 Ryan 9812 Brian CREATE: Code:

Designation code that represents the designation. Refers to designation master (lookup) table C2 C1 C1

join_date Date of joining

supervisor_id Employee id of supervisor

12-1-2004 12-12-2000 3251 12-12-2008 4562

SQL> create table employee_portfolio (emp_id varchar2(10),emp_name varchar2(30),designation varchar2 (20) ,join_date date,supervisor_id varchar2(20), foreign key(designation) references master_designat ion_details(designation),unique(emp_id)); Table created.

INSERT Code:
SQL> insert into employee_portfolio values ('&emp_id','&emp_name','&designation',to_date('&join_date ','dd-mm-yyyy'),'&supervisor_id'); Enter value for emp_id: 3251 Enter value for emp_name: Mark Enter value for designation: C2 Enter value for join_date: 12-1-2004 Enter value for supervisor_id: old 1: insert into employee_portfolio values ('&emp_id','&emp_name','&designation',to_date('&join_ new 1: insert into employee_portfolio values ('3251','Mark','C2',to_date('12-1-2004','dd-mm-yyyy') 1 row created.

---C2 C1 C1 12-JAN-04 12-DEC-00 3251 12-DEC-08 4562 emp_id Unique identifier of employee whose skills and proficiency is recorded.'&designation'.to_date('12-12-2000'.'&designation'.'Ryan'.'C1'.'dd-mm-yyyy 1 row created.'C1'. SQL> / Enter value for emp_id: 9812 Enter value for emp_name: Brian Enter value for designation: C1 Enter value for join_date: 12-12-2008 Enter value for supervisor_id: 4562 old 1: insert into employee_portfolio values ('&emp_id'. EMP_ID EMP_NAME SUPERVISOR_ID ---------.to_date('&join_ new 1: insert into employee_portfolio values ('9812'.SQL> / Enter value for emp_id: 4562 Enter value for emp_name: Ryan Enter value for designation: C1 Enter value for join_date: 12-12-2000 Enter value for supervisor_id: 3251 old 1: insert into employee_portfolio values ('&emp_id'.'&emp_name'.--------. Refers to skill master (lookup) table C JAV DES date_effective Date when employee got the skill prof_level Proficiency level of given employee for given skill. of years of experience the employee has on the given skill 12-12-2006 12-12-2004 12-12-2008 E1 E2 E0 3 4 0 . Takes values E0 thru E4 exp_years No.--------------------------------------------3251 Mark 4562 Ryan 9812 Brian Employee_Skill DESIGNATION JOIN_DATE -------------------.'Brian'.to_date('12-12-2008'.to_date('&join_ new 1: insert into employee_portfolio values ('4562'.'dd-mm-yyyy' 1 row created. Refers to employee master table.'&emp_name'. 3251 3251 4562 CREATE skill_id Unique identifier of skill for which employee’s proficiency level is recorded. SELECT Code: SQL> select * from employee_portfolio.

'dd-mm-yyyy').'E1'.date_effective date.to_date('&date_effective'.'dd-mm-y new 1: insert into employee_skill values ('3251'.'E2'.'&skill_id'. SELECT Code: SQL> select * from employee_skill.foreign key(emp_id) references employee_portfolio(emp_id)).'dd-mm-y new 1: insert into employee_skill values ('3251'.'dd-mm-yyyy'). EMP_ID EXP_YEARS SKILL_ID DATE_EFFE PROF_LEVEL .to_date('12-122006'.'&prof_level'. INSERT Code: SQL> insert into employee_skill values ('&emp_id'.'JAV'.'3') 1 row created.exp_years varchar2(20). SQL> / Enter value for emp_id: 3251 Enter value for skill_id: JAV Enter value for date_effective: 12-12-2004 Enter value for prof_level: E2 Enter value for exp_years: 4 old 1: insert into employee_skill values ('&emp_id'.Code: SQL> create table employee_skill (emp_id varchar2(20).prof _level varchar2(20).'dd-mmyyyy').to_date('12-122008'.'E0'.'&skill_id'.'&skill_id'.to_date('12-122004'.to_date('&date_effective'. Table created. SQL> / Enter value for emp_id: 4562 Enter value for skill_id: DES Enter value for date_effective: 12-12-2008 Enter value for prof_level: E0 Enter value for exp_years: 0 old 1: insert into employee_skill values ('&emp_id'.'DES'.'4' 1 row created. Enter value for emp_id: 3251 Enter value for skill_id: C Enter value for date_effective: 12-12-2006 Enter value for prof_level: E1 Enter value for exp_years: 3 old 1: insert into employee_skill values ('&emp_id'.to_date('&date_effective'.to_date('&date_effective'.skill_id varchar2(30).'0' 1 row created.'dd-mm-yyyy').'dd-mm-y new 1: insert into employee_skill values ('4562'.'&skill_id'.'&exp_years').'C'.

SQL> / Enter value for project_id: 2078 Enter value for date_start: 1-1-2007 Enter value for date_end: 12-12-2007 Enter value for name: Yahoo Development old 1: insert into employee_project values('&project_id'.to_date('1-1-2007'.'dd-mm-yyyy').'dd-mm-yyyy').'ddmm-yyyy'). Enter value for project_id: 2056 Enter value for date_start: 1-1-2008 Enter value for date_end: Enter value for name: Google Testing old 1: insert into employee_project values('&project_id'.--------------12-DEC-06 E1 12-DEC-04 E2 12-DEC-08 E0 project_id Unique identifier of project whose team is enlisted in the table 2056 2078 date_start Date when project started 1-1-2008 1-1-2007 date_end Date when project ended / ends 12-12-2007 Name Name of project Google Testing Yahoo Development CREATE Code: SQL> create table employee_project(project_id varchar2(20).date_end date.to_date('1-1-2008'.to_date('12-121 row created.to_date('&date_start'.----------------3251 C 3 3251 JAV 4 4562 DES 0 Employee_Project --------.---------------------------------.'&Name').'dd-mm-yyyy').'dd-mm-yyyy').to_date('&date_start'. SELECT Code: .to_date(' &date_end'. INSERT Code: SQL> insert into employee_project values('&project_id'.to_da new 1: insert into employee_project values('2056'.to_date(''.date_start date.to_date('&date_start'.Name varchar2(30)).to_da new 1: insert into employee_project values('2078'. Table created.-------------------.'dd1 row created.'ddmm-yyyy').

to_date('&date_start'.to_date('&date_start'.--------01-JAN-08 01-JAN-07 12-DEC-07 NAME -----------------------------Google Testing Yahoo Development emp_id Unique identifier of employee worked /works in the project.'&project_id'.to_date('&date_start'.to_ 1 row created.'dd-mm-yyyy').'&project_id'. date_end date. Table created.'ddnew 1: insert into employee_project_team values('3251'.to_date('&date_end'.foreign key (project_id) references employee_project(project_id)).role_id varchar2(20).SQL> select * from employee_project.'&role_id').'dd- .foreign key(emp_id) references Employee_portfolio(emp_id). SQL> / Enter value for emp_id: 3251 Enter value for project_id: 2056 Enter value for date_start: 12-12-2008 Enter value for date_end: Enter value for role_id: MGR old 1: insert into employee_project_team values('&emp_id'.to_date('1-12008'.project_id varchar2(30).'2056'.'dd-mm-y yyy').date_start date. Enter value for emp_id: 3251 Enter value for project_id: 2056 Enter value for date_start: 1-1-2008 Enter value for date_end: 11-12-2008 Enter value for role_id: DES old 1: insert into employee_project_team values('&emp_id'. INSERT Code: SQL> insert into employee_project_team values('&emp_id'. PROJECT_ID -------------------2056 2078 Employee_Project_Team DATE_STAR DATE_END --------.'&project_id'. Refers to employee table 3251 3251 4562 3251 CREATE Code: project_id Unique identifier of project whose team is enlisted in the table. Refers to Projects table 2056 2056 2056 2078 date_start Date when employee got into project in the given role 1-1-2008 12-12-2008 12-12-2008 1-1-2007 date_end Date when employee was released from project if any 11-12-2008 role_id Role played by employee in project 12-12-2007 DES MGR DEV DES SQL> create table Employee_project_team(emp_id varchar2(20).'dd-mm-yyyy').

'dd-mm-yyyy').'dd-mm-yyyy').'ddnew 1: insert into employee_project_team values('3251'.--------.to_date('&date_start'.'2056'.to_date('1-12007'.to_ 1 row created.to_date('&date_start'. SELECT Code: SQL> select * from employee_project_team. SQL> / Enter value for emp_id: 4562 Enter value for project_id: 2056 Enter value for date_start: 12-12-2008 Enter value for date_end: Enter value for role_id: DEV old 1: insert into employee_project_team values('&emp_id'. EMP_ID ROLE_ID ---------------------------------3251 3251 4562 3251 Master Tables PROJECT_ID DATE_STAR DATE_END -----------------------------.to_date('1212-2008'.'2078'.'&project_id'.'dd-mm-yyyy').'2056'.----2056 2056 2056 2078 01-JAN-08 11-DEC-08 DES 12-DEC-08 MGR 12-DEC-08 DEV 01-JAN-07 12-DEC-07 DES Master_Skill skill_id Name C C Programming JAV Java Programming DES Software Design TEST Software Testing OOP Object Oriented Programming CREATE .to_date('1212-2008'.--------.'&project_id'. SQL> / Enter value for emp_id: 3251 Enter value for project_id: 2078 Enter value for date_start: 1-1-2007 Enter value for date_end: 12-12-2007 Enter value for role_id: DES old 1: insert into employee_project_team values('&emp_id'.t 1 row created.new 1: insert into employee_project_team values('3251'.'ddnew 1: insert into employee_project_team values('4562'.t 1 row created.

primary key(skill_id)).'Java Programming') SELECT Code: SQL> select * from master_skill.'Software Testing') skill_id: DES skill_name: Software Design into master_skill values('&skill_id'.'Software Design') skill_id: JAV skill_name: Java Programming into master_skill values('&skill_id'. SQL> / Enter value for Enter value for old 1: insert new 1: insert 1 row created.'&skill_name') into master_skill values('DES'. skill_id: OOP skill_name: Object Oriented Programming into master_skill values('&skill_id'. Table created.skill_name varchar2(30).'C Programming') 1 row created.'&skill_name') into master_skill values('OOP'. SKILL_ID -------------------C JAV DES Test OOP SKILL_NAME -----------------------------C Programming Java Programming Software Design Software Testing Object Oriented Programming . SQL> / Enter value for Enter value for old 1: insert new 1: insert 1 row created.'Object Oriented Programming') skill_id: Test skill_name: Software Testing into master_skill values('&skill_id'. SQL> / Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> / Enter value for Enter value for old 1: insert new 1: insert 1 row created.'&skill_name') into master_skill values('Test'.Code: SQL> create table master_skill(skill_id varchar2(20). Enter value for skill_id: C Enter value for skill_name: C Programming old 1: insert into master_skill values('&skill_id'. INSERT Code: SQL> insert into master_skill values('&skill_id'.'&skill_name') into master_skill values('JAV'.'&skill_name') new 1: insert into master_skill values('C'.'&skill_name').

INSERT Code: SQL> insert into master_designation_details values('&designation'. SQL> / Enter value for designation: C4 Enter value for designation_name: Director old 1: insert into master_designation_details values('&designation'.'&designation_name') new 1: insert into master_designation_details values('C1'.'Engineer') 1 row created. Table created.'Analyst') 1 row created. primary key(designation)).Master_Designation_details Designation Name C1 Engineer C2 Analyst C3 Consultant C4 Director VP Vice President CREATE Code: SQL> create table master_designation_details(designation varchar2(20).'&designation_name') new 1: insert into master_designation_details values('C2'.'&designation_name') new 1: insert into master_designation_details values('C4'.'Consultant') 1 row created. SQL> / Enter value for designation: C3 Enter value for designation_name: Consultant old 1: insert into master_designation_details values('&designation'. Enter value for designation: C1 Enter value for designation_name: Engineer old 1: insert into master_designation_details values('&designation'.'Director') .'&designation_name').designation_name varchar2(30).'&designation_name') new 1: insert into master_designation_details values('C3'. SQL> / Enter value for designation: C2 Enter value for designation_name: Analyst old 1: insert into master_designation_details values('&designation'.

DESIGNATION -------------------C1 C2 C3 C4 VP Master_Role DESIGNATION_NAME -----------------------------Engineer Analyst Consultant Director Vice President role_id Name DES Designer MGR Manager DEV Developer SC Site Coordinator TST Tester CREATE Code: SQL> create table master_role(role_id varchar2(20).'Designer') 1 row created.'&role_name') into master_role values('MGR'.role_name varchar2(30).'&designation_name') new 1: insert into master_designation_details values('VP'.'&role_name') new 1: insert into master_role values('DES'.'&role_name'). Table created. SQL> / Enter value for Enter value for old 1: insert new 1: insert role_id: MGR role_name: Manager into master_role values('&role_id'. Enter value for role_id: DES Enter value for role_name: Designer old 1: insert into master_role values('&role_id'.'Vice President') 1 row created. SELECT Code: SQL> select * from master_designation_details.1 row created.'Manager') . SQL> / Enter value for designation: VP Enter value for designation_name: Vice President old 1: insert into master_designation_details values('&designation'. INSERT Code: SQL> insert into master_role values('&role_id'.primary key(role_id)).

'Tester') role_id: SC role_name: Site Coordinator into master_role values('&role_id'. Do not forget to explicitly articulate any assumptions you make Add sufficient sample data to the above data (do not remove any existing data) – so that you can demonstrate good output for all the following SQL and DML that you will design. Inputs are specifically left as generic with examples so that youmay demonstrate results for multiple inputs where needed 1. SQL> / Enter value for Enter value for old 1: insert new 1: insert 1 row created.'Site Coordinator') role_id: DEV role_name: Developer into master_role values('&role_id'. SQL> / Enter value for Enter value for old 1: insert new 1: insert 1 row created.1 row created. Find the names of all employees who are currently in projects and are whose designation . SQL> / Enter value for Enter value for old 1: insert new 1: insert 1 row created.'&role_name') into master_role values('TST'.'&role_name') into master_role values('DEV'. role_id: TST role_name: Tester into master_role values('&role_id'.'&role_name') into master_role values('SC'.'Developer') SELECT Code: SQL> select * from master_role. ROLE_ID -------------------DES MGR DEV SC TST ROLE_NAME -----------------------------Designer Manager Developer Site Coordinator Tester Answer the following     For all questions – following standard procedure starting from defining the problem to showing sample output / dry run.

If date_end is null. Same employee is active on multiple projects? b. Employee_Project_Team has details of all employees who were / are working on a given project c. Employee_portfolio table has employee details – name and designation b. No employees match the requirement o Sample scenario . then the project is the currently active project for the given employee o Input – A designation code o Output – List of names of employees   a. Criteria – emp_id in output of previous query .is as given (say ‘C1’). With the given designation b. Multiple employees match the requirement c.Input ‘C1’ => Output ‘Ryan’ STEP 2: Solution Approach: • Find employees who are currently active:      o Criteria – end_date is null in employee_project_team table o Output required for further matching – emp_id o Intermediate solution:  SELECT emp_id from employee_ project_team  where date_end is null • Get employee name based on previously got ids   o Criteria – designation is as given in input on the employee table o Addl. Who are currently active in at least one project o Special considerations    a. STEP 1: Problem Definiton: o Context    a.

4562 2. Insertion is done above just to show mapping between these steps Also note that intermediate solution testing is skipped as this is a solution for a paper test. Input ‘C2’ => Output ‘Mark’ 2.further filter on employee returns no result NOTE: Dry run will vary if approach is reversed STEP 5: Translation Approach The translation approach is depicted as sub-bullets (Intermediate Solution) in STEP 2: Solution approach. Ryan 3. Mapped names are: Mark. . C1 – further filter on employee returns Ryan b. NOTE: Though intermediate solution is inserted above – it is expected that the part is filled only at this point of time. STEP 6: Final Query Code: SQL> select emp_name from employee_portfolio where designation = 'C1'and emp_id in (SELECT emp_id from employee_project_team where date_end is null).    o Output required: emp_name o Intermediate solution:  select emp_name from employee_portfolio where designation = ?  and emp_id in ?previous_output? NOTE: Approach can be reversed to filter first by designation as well STEP 3: Sample Test Cases 1. Input ‘VP’ => Output None NOTE Missing test case: multiple output scenario Need to add data to demonstrate multiple records This step can also be interchanged with step 2 STEP 4: Dry Run 1. C2 – further filter on employee returns Mark c. Intermediate result of query irrespective of input is 3251. If input is    a. Input ‘C1’ => Output ‘Ryan’ 3. VP .

Project table has name of project o Input – A skill id o Output – List of names of projects and corresponding number of employees  a.emp_id where designation = 'C1' and date_end is null.e mp_id = e. EMP_NAME -----------------------------Ryan OR Code: SQL> select emp_name from employee_portfolio e inner join (SELECT emp_id.EMP_NAME -----------------------------Ryan OR Code: SQL> select distinct emp_name from employee_portfolio e inner join employee_project_team pe on pe. date_end from employee_pr oject_team where date_end is null) pe on pe. find the number of employees who have a particular skill (say ‘JAV’). EMP_NAME -----------------------------Ryan 2. For each project. STEP 1: Problem Definiton: o Context    a. Project_Team table has details of all employees who were / are working on a given project c. Employee_Skills table has details about skills of a given employee b.emp_id where designation = 'C1' and date_end is null. with the given skill o Special considerations .emp_id = e.

The project may have no team at all b. Yahoo Development 0 o STEP 2: Final Query Code: SQL> SELECT p.in this case he should not be double counted e. Google Testing 1 b.emp_id where skill_id = 'JAV' or skill_id is null group by p. count(distinct pe.emp_id) No_of_Employee from employee_project p left outer join employee_project_team pe on p. Google Testing 1 b. count(emp_id) No_of_Employee from employee_project p left outer join (SELECT di stinct project_id.project_id left outer join employee_skill es on es.project_id group by p. . The same employee may have been on multiple roles in a given project .Input ‘DES’ => Output   a.name 2 / NAME NO_OF_EMPLOYEE -----------------------------.name. emp_id from employee_project_team where emp_id in (select emp_id from employee_sk ill where skill_id = 'JAV')) pe on p. None of the team may have the skill c.project_id = pe. Multiple employees have skills in the same project d.Input ‘JAV’ => Output   a.name.e mp_id = pe.     a. o Sample scenario .project_id = pe.-------------Google Testing 1 Yahoo Development 1 OR Code: SQL> SELECT p.name. The same employee may have worked on multiple projects – in this case double counting is fine.. Yahoo Development 1 o Sample scenario .

project_id group by p.emp_id where skill_id = 'JAV' and prof_level = 'E2' and e. no rows selected OR Code: SQL> SELECT emp_name.emp_id not in (SELECT emp_id from empl oyee_project_team where date_end is null).-------------Google Testing 1 Yahoo Development 1 Typical Mistakes o If count(*) is done instead then all places where 0 is expected will return 1 o If outer join not done some records will be skipped o While doing outer join if OR skill_id is null check is not added some records will be skipped o If group by not done correctly or if additional fields selected etc. query will not execute o … and many more 3. exp_years from employee_portfolio e inner join employee_skill es on e.emp_id where skill_id = 'JAV' and prof_level = 'E2' and NOT EXISTS (SELECT 1 FROM employee_proje ct_team pt where pt.emp_id from employee_project_team pt INNER JOIN employee_skill es ON es. NAME NO_OF_EMPLOYEE -----------------------------. count(pe.emp_id = e.emp_id = es. pt.emp_id = es.-------------Google Testing 1 Yahoo Development 1 OR Code: SQL> SELECT p.NAME NO_OF_EMPLOYEE -----------------------------.emp_id where skill_id = 'JAV') pe on p.emp_id) No_of_Employee from employee_project p left outer join (SELECT distinct project_id.name.project_id = pe. Find all people (name and total experience in given skill) who have a particular skill at a particular proficiency (say ‘JAV’ – ‘E2’) who are not currently in any project.name. exp_years from employee_portfolio e inner join employee_skill es on e.emp_id and date_end is null). . Code: SQL> SELECT emp_name.em p_id = pt.

project_id where skill_id = 'JAV' and prof_level = 'E2' and pt.----------------Mark 4 Analyst Google Testing Typical Mistakes o If date_end criteria is not used the same employee will appear multiple times for each of the past projects (A valid assumption is that there is a max of one current project in which employee works) o If inner join done on project_team or project. EMP_NAME EXP_YEARS DESIGNATION_NAME PROJECT_NAME -----------------------------.emp_name = 'Ryan' and e. Find all people (name of employee.name project_name from employee_portfolio e i nner join employee_skill es on e.-------------------.emp_id left outer join master_designation_details d on d.emp_id not in (SELECT emp_id from employee_project _team where date_end is null).no rows selected 4.emp_id = e.----------------------------.emp_id = es. exp_years. p. Code: SQL> SELECT emp_name.date_end is null.emp_id left outer join employee_project p on pt.designation = e.supervisor_ id = sup. EMP_NAME -----------------------------Brian 6. designation name. current project name and role name if any) who are second level reportees of a given employee (say ‘Mark’) Code: .project_id = p.designation left outer join employee_project_team pt on pt. project name and total experience in given skill) who have a particular skill at a particular proficiency (say ‘JAV’ – ‘E2’). d. Find all employees who report to an employee (say ‘Ryan’) who are not currently in any project Code: SQL> select e.designation_name. Find the employees (name. then people not in any projects will not be listed o While it may be okay to assume that there are matching designation rows and hence inner join is also okay – inner join on projects is not acceptable 5.emp_name from employee_portfolio e inner join employee_portfolio sup on e.emp_id where sup. designation.

Provide complete details of all current and previous projects of all employees reporting to a given employee (say ‘Mark’) Code: SQL> select e.*.emp_id and pt.------------------. e.--------.-----------------------------. EMP_NAME DESIGNATION_NAME PROJECT_NAME ROLE_NAME -----------------------------.----------------------------. sup.emp_name supervisor_n ame. EMP_ID EMP_NAME DESIGNATION SUPERVISOR_NAME SUPERVISOR_DESIGNATI ---------.-----------------------------.* from employee_portfolio e inner join employee_portfolio sup on e.supervisor_id = sup2.*.emp_id left outer joi n employee_project p on pt.emp_name = 'Mark'. supervisor designation) List them by designations (higher levels first) and within that all names should be alphabetical. pt.date_end i s null left outer join employee_project p on pt.supervisor_id = sup.designation. supervisor id.supervisor_id = sup. name. p.designation left outer join employee_project_team pt on pt. supervisor name.emp_name.emp_name = 'Mark'.designation supervisor_designation from employee_portfolio e left outer join employee_portf olio sup on e. p.designation desc.--4562 3251 8.------Brian Engineer 7. Code: SQL> select e.emp_id left outer join master_designation_details d on d.superv isor_id = sup.------ . e. sup.role_id where sup2.role_name from employee_portfoli o e inner join employee_portfolio sup on e.emp_id supervisor_id.designatio n = e.project_id left outer join master_rol e r on pt.SQL> select e.-------------------.project_id = p.emp_id = e.emp_name. e.name project_name.emp_id.emp_id left outer join employee_project_team pt on pt.designation_name.emp_id inner join employee_portfolio sup2 on sup.role_id = r.-----------------------------.-----------------------------------------3251 Mark C2 9812 Brian C1 Ryan C1 4562 Ryan C1 Mark C2 SUPERVISOR ---------.emp_name.project_id = p.emp_id order by e. Create report with the following details of all employees (employee id. designation. d.project_id where sup.emp_id = e. sup. r. EMP_ID EMP_NAME DESIGNATION JOIN_DATE SUPERVISOR_ID PROJECT_ID DATE_STAR DATE ---------.

''). Find the employee who has the maximum number of direct reportees. 11. Write the necessary DML to add the new employee details and change the hierarchy of all reportees of the original employee to the new employee. Code: SQL> select s. s. 1 row updated.emp_id.emp_id group by s.'12-MAY2004'. INSERT: Code: SQL> insert into employee_portfolio values('1234'. 0 rows updated.emp_name from employee_portfolio s inner join employee_portfolio e on e. An employee (say ‘Mark’) is handing over charge to a new employee (say ‘Terry’). UPDATE: Code: SQL> UPDATE employee_portfolio set supervisor_id='1234' where supervisor_id='3251'. s. 10.emp_name having count(*) = ( select max(cnt) from (selec t count(*) cnt from employee_portfolio where supervisor_id is not null group by supervisor_id) emp_ cnt ).sup ervisor_id = s.'Terry'. 1 row created.'C2'. Check for all projects that have been ended in the past (end_date not null) and update the project role end date of all employees who are active (end_date null) to the actual end date of the project Code: SQL> update employee_project_team set date_end = (select date_end from employee_project where date_e nd is not null) where project_id =(select project_id from employee_project where date_end is not nul l) and date_end is null.4562 2056 Ryan 01-JAN-08 C1 Google Testing 12-DEC-00 3251 9.emp_id. EMP_ID ---------1234 4562 EMP_NAME -----------------------------Terry Ryan .

-----------------------------3251 Mark . project_id HAVING count(distinct role_id) = (SELECT max(num_roles) max_roles FROM (SELECT emp_id. emp_name from employee_project_team pt inner join employee_portfolio e on e. emp_name. project_id.emp_id.emp_id.12. EMP_ID EMP_NAME ---------. count(distinct role_id) num_roles from employee_project_team group by emp_id.emp_id group by e.emp_id = pt. project_id) emp_roles). Code: SQL> select distinct e. Find the employees who have worked on the same project in the most number of roles.