0% found this document useful (0 votes)
624 views16 pages

Project

SQL Project

Uploaded by

sonukumarjaiswar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
624 views16 pages

Project

SQL Project

Uploaded by

sonukumarjaiswar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 16

Project On :

ScienceQtech
Employee Performance Mapping

By:
Sonukumar Rameschandra Jaiswar
BA - SQL
[email protected]
Description

ScienceQtech is a startup that works in the Data Science field. ScienceQtech has worked on fraud
detection, market basket, self-driving cars, supply chain, algorithmic early detection of lung cancer,
customer sentiment, and the drug discovery field. With the annual appraisal cycle around the corner, the
HR department has asked you (Junior Database Administrator) to generate reports on employee details,
their performance, and on the project that the employees have undertaken, to analyze the employee
database and extract specific data based on different requirements.

Objective:

To facilitate a better understanding, managers have provided ratings for each employee which will help
the HR department to finalize the employee performance mapping. As a DBA, you should find the
maximum salary of the employees and ensure that all jobs are meeting the organization's profile
standard. You also need to calculate bonuses to find extra cost for expenses. This will raise the overall
performance of the organization by ensuring that all required employees receive training.

***The task

1. 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.

2.Create an ER diagram for the given employee database.


3.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.
4.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

 less than two

SELECT EMP_ID, FIRST_NAME, LAST_NAME, GENDER,DEPT,EMP_RATING FROM emp_record_table


WHERE EMP_RATING<2;

 greater than four

SELECT EMP_ID, FIRST_NAME, LAST_NAME, GENDER,DEPT,EMP_RATING FROM emp_record_table


WHERE EMP_RATING>4;
 between two and four

SELECT EMP_ID, FIRST_NAME, LAST_NAME, GENDER,DEPT,EMP_RATING FROM emp_record_table


WHERE EMP_RATING BETWEEN 2 AND 4;
5. 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) ASNAME FROM emp_record_table WHERE DEPT =


"FINANCE";

6. Write a query to list only those employees who have someone reporting to them. Also, show the
number of reporters (including the President).

SELECT m.EMP_ID,m.FIRST_NAME,m.LAST_NAME,m.ROLE,
m.EXP,COUNT(e.EMP_ID) as "EMP_COUNT"
FROM emp_record_table m
INNER JOIN emp_record_table e
ON m.EMP_ID = e.MANAGER_ID
GROUP BY m.EMP_ID
ORDER BY m.EMP_ID;

05:38:17 SELECT m.EMP_ID,m.FIRST_NAME,m.LAST_NAME,m.ROLE, m.EXP,COUNT(e.EMP_ID) as


"EMP_COUNT" FROM emp_record_table m INNER JOIN emp_record_table e ON m.EMP_ID =
e.MANAGER_ID GROUP BY m.EMP_ID ORDER BY m.EMP_ID LIMIT 0, 1000 Error Code: 1055.
Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column
'employee.m.FIRST_NAME' which is not functionally dependent on columns in GROUP BY clause; this is
incompatible with sql_mode=only_full_group_by 0.000 sec

SELECT @@sql_mode;

SET @@sql_mode = SYS.LIST_DROP(@@sql_mode, 'ONLY_FULL_GROUP_BY');


SELECT @@sql_mode;

SELECT m.emp_id, m.first_name MGR_NAME, COUNT(e.first_name) AS reportees


FROM emp_record_table e, emp_record_table m
WHERE e.manager_id = m.emp_id
GROUP BY m.emp_id;

7. 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 emp_id, first_name, dept


FROM emp_record_table
WHERE dept = 'HEALTHCARE'
UNION
SELECT emp_id, first_name, dept
FROM emp_record_table
WHERE dept = 'FINANCE';
8. 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_EMP_RATING
FROM emp_record_table;
9. 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 emp_id, FIRST_NAME, LAST_NAME, ROLE, DEPT, salary,


MIN(salary) OVER (PARTITION BY role) AS MIN_salary,
MAX(salary) OVER (PARTITION BY role) AS MAX_salary
FROM emp_record_table;

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

SELECT emp_id, FIRST_NAME, LAST_NAME, ROLE, DEPT, exp,


RANK() OVER(ORDER BY exp DESC) emp_exp_rank,
DENSE_RANK() OVER(ORDER BY exp DESC) emp_exp_dense_rank
FROM emp_record_table;
11. 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 v_emp AS

SELECT * FROM emp_record_table


WHERE salary > 6000;Then execute the below syntax

SELECT * FROM v_emp;


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

SELECT e.emp_id, e.first_name, e.exp


FROM emp_record_table e
WHERE e.emp_id IN
(SELECT s.emp_id
FROM emp_record_table s
WHERE s.exp > 10);
13. 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();

14. 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'.


DELIMITER &&

CREATE FUNCTION Employee_ROLE(

EXP int

RETURNS VARCHAR(40)

DETERMINISTIC

BEGIN

DECLARE Employee_ROLE VARCHAR(40);

IF EXP>12 AND 16 THEN

SET Employee_ROLE="MANAGER";

ELSEIF EXP>10 AND 12 THEN

SET Employee_ROLE ="LEAD DATA SCIENTIST";

ELSEIF EXP>5 AND 10 THEN

SET Employee_ROLE ="SENIOR DATA SCIENTIST";

ELSEIF EXP>2 AND 5 THEN

SET Employee_ROLE ="ASSOCIATE DATA SCIENTIST";

ELSEIF EXP<=2 THEN

SET Employee_ROLE ="JUNIOR DATA SCIENTIST";

END IF;

RETURN (Employee_ROLE);

END &&

SELECT EXP,Employee_ROLE(EXP)
FROM data_science_team;
15. 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.

CREATE INDEX idx_first_name ON emp_record_table(FIRST_NAME(20));


SELECT * FROM emp_record_table WHERE FIRST_NAME='Eric';

16. 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).
update emp_record_table set salary=(select salary +(select salary*.05*EMP_RATING))
SELECT *FROM emp_record_table;

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

update emp_record_table set salary=(select salary +(select salary*.05*EMP_RATING))

SELECT *FROM emp_record_table;


Thank You

You might also like