The document contains SQL queries and procedures to analyze employee data. It creates databases and tables, performs selects, filters, groups, joins, ranks, aggregates, and defines a stored procedure. The queries retrieve employee data from different tables, filter by various criteria like department, experience, rating, and salary ranges, perform calculations on the data, and return the results.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
45 views3 pages
Assignment 1 Zaid
The document contains SQL queries and procedures to analyze employee data. It creates databases and tables, performs selects, filters, groups, joins, ranks, aggregates, and defines a stored procedure. The queries retrieve employee data from different tables, filter by various criteria like department, experience, rating, and salary ranges, perform calculations on the data, and return the results.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3
----------------TASK 1 --------------------
create database employee;
------------------------------------------- use employee; -------------------------------------------
create table data_science_team (
EMP_ID varchar(20), FIRST_NAME varchar(20), LAST_NAME varchar(20), GENDER varchar(20), ROLE varchar(20), DEPT varchar(20), EXP int, COUNTRY varchar(20), CONTINENT varchar(20) ); -------------------------------------------
select * from data_science_team;
------------------------------------------- select * from emp_record_table; ------------------------------------------- select * from proj_table; ------------------------------------------- ----------------TASK 3 -------------------- select EMP_ID, FIRST_NAME, LAST_NAME, GENDER, DEPT from emp_record_table; ---------------------------------- ----------------TASK 4 -------------------- select EMP_ID, FIRST_NAME, LAST_NAME, GENDER, DEPT from emp_record_table where EMP_RATING <2; ---------------------------------- select EMP_ID, FIRST_NAME, LAST_NAME, GENDER, DEPT from emp_record_table where EMP_RATING >4; ---------------------------------- select EMP_ID, FIRST_NAME, LAST_NAME, GENDER, DEPT from emp_record_table where EMP_RATING between 2 and 4; -------------------------------------------- select EMP_ID, FIRST_NAME, LAST_NAME, GENDER, DEPT, case when emp_rating <2 then ' less than 2' when emp_rating >4 then 'greater than 4' when emp_rating between 2 and 4 then 'Between 2 and 4' else 'na' end as emp_rating_new from emp_record_table; ---------------------------------------------------------------------- ----------------TASK 5 -------------------- select concat ( FIRST_NAME, ' ', LAST_NAME) as NAME from emp_record_table where DEPT = 'finance'; ---------------------------------------------------------------- SELECT * FROM EMP_RECORD_TABLE; ---------------------------------------------------------------- ----------------TASK 6 -------------------- SELECT MANAGER_ID, count(EMP_ID) FROM EMP_RECORD_TABLE GROUP BY MANAGER_ID; ---------------------------------------------------------------- ----------------TASK 7 -------------------- select * from EMP_RECORD_TABLE where dept = 'finance' union select * from EMP_RECORD_TABLE where dept = 'healthcare'; -------------------------------------------------------------------- ----------------TASK 8 -------------------- select EMP_ID, FIRST_NAME, LAST_NAME, ROLE, DEPT, EMP_RATING, max(emp_rating) over (partition by dept) as max_Rate from emp_record_table; ------------------------------------------------------------------- ----------------TASK 9 -------------------- select role, min(salary), max(salary) from emp_record_table group by role; --------------------------------------------------------- ----------------TASK 10 -------------------- select emp_id, first_name, exp, dept, rank() over ( order by exp desc) as rnk, dense_rank() over (order by exp desc) as rnk_ from emp_record_table order by rnk; ------------------------------------------------------- ----------------TASK 11 -------------------- select emp_id, first_name, country, salary from emp_record_table where salary > 6000 order by country; ------------------------------------------------------ ----------------TASK 12 -------------------- select emp_id, first_name, exp from emp_record_table where emp_id in ( select emp_id from emp_record_table where exp > 10 ); ------------------------------------------------ ----------------TASK 13 -------------------- DELIMITER && CREATE PROCEDURE EXP3() BEGIN SELECT * FROM emp_record_table where exp > 3 ; END && ------------------------------------ call EXP3() ; ------------------------------------ ----------------TASK 16 -------------------- select emp_id, ((5/100)*EMP_RATING*SALARY) AS BONUS from emp_record_table group by emp_id; ---------------------------------------- ----------------TASK 17 -------------------- select distinct continent , country, avg(salary) over( partition by continent , country ) as avg_Sal from emp_record_table