Beruflich Dokumente
Kultur Dokumente
Main Tables
Employee
emp_id
Unique
identifier
emp_name
Name of
employee
3251
4562
9812
Mark
Ryan
Brian
Employee_Skills
emp_id
Unique
identifier of
employee
whose skills
and proficiency
is recorded.
Refers to
employee
master table.
3251
3251
4562
Project
project_id
Unique
identifier of
project whose
team is enlisted
in the table
Designation
code that
represents the
designation.
Refers to
designation
master (lookup)
table
C2
C1
C1
join_date
Date of joining
skill_id
Unique
identifier of
skill for which
employees
proficiency
level is
recorded.
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.
Takes values
E0 thru E4
exp_years
No. 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
date_start
Date when
project started
date_end
Date when
project ended /
ends
Name
Name of project
12-1-2004
12-12-2000
12-12-2008
supervisor_id
Employee id of
supervisor
3251
4562
2056
2078
1-1-2008
1-1-2007
Project_Team
emp_id
Unique
identifier of
employee
worked /works
in the project.
Refers to
employee table
3251
3251
4562
3251
project_id
Unique
identifier of
project whose
team is enlisted
in the table.
Refers to
Projects table
2056
2056
2056
2078
12-12-2007
Google Testing
Yahoo Development
date_start
Date when
employee got
into project in
the given role
date_end
Date when
employee was
released from
project if any
role_id
Role played by
employee in
project
1-1-2008
12-12-2008
12-12-2008
1-1-2007
11-12-2008
DES
MGR
DEV
DES
12-12-2007
Master Tables
Skills
skill_id
C
JAV
DES
TEST
OOP
Name
C Programming
Java Programming
Software Design
Software Testing
Object Oriented Programming
Designation
Designation
C1
C2
C3
C4
VP
Name
Engineer
Analyst
Consultant
Director
Vice President
Role
role_id
DES
MGR
DEV
SC
TST
Name
Designer
Manager
Developer
Site Coordinator
Tester
OR
select distinct emp_name from employee e inner join project_team pe
on pe.emp_id = e.emp_id where designation = 'C1'
and date_end is null
OR
select emp_name from employee e inner join
(SELECT emp_id, date_end from project_team where date_end is null) pe
on pe.emp_id = e.emp_id
where designation = 'C1' and date_end is null
STEP 7: Final Testing
This step is skipped as this solution is for a paper test with no access to actual
database.
o
STEP 6: Final Query
SELECT p.name, count(distinct pe.emp_id)
from project p left outer join project_team pe
on p.project_id = pe.project_id left outer join employee_skills es
on es.emp_id = pe.emp_id where skill_id = 'JAV' or skill_id is null
group by p.name
OR
SELECT p.name, count(emp_id) from project p left outer join
(SELECT distinct project_id, emp_id from project_team where emp_id in
(select emp_id from employee_skills where skill_id = 'JAV')) pe
on p.project_id = pe.project_id group by p.name
OR
SELECT p.name, count(pe.emp_id) from project p left outer join
(SELECT distinct project_id, pt.emp_id from project_team pt
INNER JOIN employee_skills es ON es.emp_id = pt.emp_id
where skill_id = 'JAV') pe
on p.project_id = pe.project_id group by p.name
OR
Other equivalent
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