SQL Project ScienceQtech Employee Performance Mapping...

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 14

Project On ScienceQtech Employee Performance Mapping.

Date 12-09-2023

PB BA - SQL

By Swati Sangal

The task to be performed:

Q1. Create a database named employee, then import data_science_team.csv proj_table.csv and
emp_record_table.csv into the employee database from the given resources.

create database employee;


2 Create an ER diagram for the given employee database.

---changing the datatype of emp_id----

alter table emp_record_table

modify column emp_id varchar(10);


---assigning emp_id as pk---

alter table emp_record_table

add primary key (emp_id);

alter table proj_table

modify column PROJECT_Id varchar(10);

alter table emp_record_table

modify column proj_id varchar(10);

alter table proj_table

add primary key (PROJECT_Id);

----making project id in employee table as foreign key---

alter table emp_record_table

add foreign key (PROJ_ID) references proj_table(PROJECT_ID)

elect * from emp_record_table

select * from data_science_team

----------------------------------------------------------------------------------------------------------------

alter table data_science_team

modify column emp_id varchar (10)

alter table data_science_team

add foreign key (EMP_ID) references emp_record_table(EMP_ID)


Q3. Write a query to fetch EMP_ID, FIRST_NAME, LAST_NAME, GENDER, and DEPARTMENT from the
employee record table, and make a list of employees and details of their department.

select EMP_ID, FIRST_NAME, LAST_NAME, GENDER, dept from emp_record_table

Q4.Write a query to fetch EMP_ID, FIRST_NAME, LAST_NAME, GENDER, DEPARTMENT, and


EMP_RATING if the EMP_RATING is:

less than two

greater than four

between two and four

select EMP_ID, FIRST_NAME, LAST_NAME, GENDER, DEPt, EMP_RATING from emp_record_table

where emp_rating<2 or emp_rating>4 or emp_rating between 2 and 4

Q5. Write a query to concatenate the FIRST_NAME and the LAST_NAME of employees in the Finance
department from the employee table and then give the resultant column alias as NAME.

select *, concat(first_name,' ',last_name) as Name from emp_record_table

where dept="Finance"
Q6.Write a query to list only those employees who have someone reporting to them. Also, show the
number of reporters (including the President).

select et1.emp_id, et1.first_name,et1.last_name,et1.role, count(*) from emp_record_table as ET1

inner join emp_record_table as ET2

on et1.emp_id=et2.manager_id

group by et1.emp_id, et1.first_name,et1.last_name,et1.role


Q7.Write a query to list down all the employees from the healthcare and finance departments using
union. Take data from the employee record table.

select * from emp_record_table

where dept="healthcare"

union

select * from emp_record_table

where dept="finance"

Q8 .Write a query to list down employee details such as EMP_ID, FIRST_NAME, LAST_NAME, ROLE,
DEPARTMENT, and EMP_RATING grouped by dept. Also include the respective employee rating along
with the max emp rating for the department.

select EMP_ID, FIRST_NAME, LAST_NAME, ROLE, DEPt, EMP_RATING ,

max(emp_rating) over(partition by dept) as max

from emp_record_table

order by dept
Q9. Write a query to calculate the minimum and the maximum salary of the employees in each role.
Take data from the employee record table.

select role, max(salary), min(salary) from emp_record_table

group by role

Q10. Write a query to assign ranks to each employee based on their experience. Take data from the
employee record table.

select *, rank() over(order by exp desc) as rank__ from emp_record_table


Q11. Write a query to create a view that displays employees in various countries whose salary is more
than six thousand. Take data from the employee record table.

CREATE VIEW employees_in_various_countries AS

SELECT EMP_ID,FIRST_NAME,LAST_NAME,COUNTRY,SALARY FROM emp_record_table

WHERE SALARY>6000;

SELECT *FROM employees_in_various_countries


Q12. Write a nested query to find employees with experience of more than ten years. Take data from
the employee record table.

select first_name, last_name from (

select * from emp_record_table

where exp>10) as B

Q13 Write a query to create a stored procedure to retrieve the details of the employees whose
experience is more than three years. Take data from the employee record table.

DELIMITER &&

CREATE PROCEDURE get_experience_details()

BEGIN

SELECT EMP_ID,FIRST_NAME,LAST_NAME,EXP FROM emp_record_table WHERE EXP>3;

END &&

CALL get_experience_details()

Q14. Write a query using stored functions in the project table to check whether the job profile
assigned to each employee in the data science team matches the organization’s set standard.

The standard being:

For an employee with experience less than or equal to 2 years assign 'JUNIOR DATA SCIENTIST',

For an employee with the experience of 2 to 5 years assign 'ASSOCIATE DATA SCIENTIST',

For an employee with the experience of 5 to 10 years assign 'SENIOR DATA SCIENTIST',

For an employee with the experience of 10 to 12 years assign 'LEAD DATA SCIENTIST',

For an employee with the experience of 12 to 16 years assign 'MANAGER'.


select *, case when exp <2 then 'JUNIOR DATA SCIENTIST'

when exp<=5 then 'ASSOCIATE DATA SCIENTIST'

when exp<=10 then 'SENIOR DATA SCIENTIST'

when exp<=12 then 'Lead DATA SCIENTIST'

else "Manager" end as Status

from emp_record_table

Q15 Create an index to improve the cost and performance of the query to find the employee whose
FIRST_NAME is ‘Eric’ in the employee table after checking the execution plan.

alter table emp_record_table

modify column first_name varchar(100)

explain select * from emp_record_table

where first_name="Eric"

create index ix_lastname on emp_record_table(first_name)

Q16 Write a query to calculate the bonus for all the employees, based on their ratings and salaries
(Use the formula: 5% of salary * employee rating).

select *, (5*salary*emp_rating)/100 as bonus from emp_record_table


Q17 Write a query to calculate the average salary distribution based on the continent and country.
Take data from the employee record table.

select continent, country, avg(salary) from emp_record_table

group by continent, country

You might also like