create table employee
( emp_ID int
, emp_NAME varchar(50)
, DEPT_NAME varchar(50)
, SALARY int);
insert into employee values(101, 'Mohan', 'Admin', 4000);
insert into employee values(102, 'Rajkumar', 'HR', 3000);
insert into employee values(103, 'Akbar', 'IT', 4000);
insert into employee values(104, 'Dorvin', 'Finance', 6500);
insert into employee values(105, 'Rohit', 'HR', 3000);
insert into employee values(106, 'Rajesh', 'Finance', 5000);
insert into employee values(107, 'Preet', 'HR', 7000);
insert into employee values(108, 'Maryam', 'Admin', 4000);
insert into employee values(109, 'Sanjay', 'IT', 6500);
insert into employee values(110, 'Vasudha', 'IT', 7000);
insert into employee values(111, 'Melinda', 'IT', 8000);
insert into employee values(112, 'Komal', 'IT', 10000);
insert into employee values(113, 'Gautham', 'Admin', 2000);
insert into employee values(114, 'Manisha', 'HR', 3000);
insert into employee values(115, 'Chandni', 'IT', 4500);
insert into employee values(116, 'Satya', 'Finance', 6500);
insert into employee values(117, 'Adarsh', 'HR', 3500);
insert into employee values(118, 'Tejaswi', 'Finance', 5500);
insert into employee values(119, 'Cory', 'HR', 8000);
insert into employee values(120, 'Monica', 'Admin', 5000);
insert into employee values(121, 'Rosalin', 'IT', 6000);
insert into employee values(122, 'Ibrahim', 'IT', 8000);
insert into employee values(123, 'Vikram', 'IT', 8000);
insert into employee values(124, 'Dheeraj', 'IT', 11000);
/*select * from employee;*/
-- Fetch the first 2 employees from each department to join the company.
/*Select * from(
Select *, Row_number() over(partition by DEPT_NAME Order by emp_ID) as ordering
from employee)x
where x.ordering<3*/
-- Fetch the top 3 employees in each department earning the max salary.
/*Select *
from(
Select e.*, RANK() over(partition by e.DEPT_NAME Order by e.salary desc) as highest_sal
from employee e) x
where x.highest_sal<4*/
-- Checking the different between rank, dense_rnk and row_number window functions:
/*Select e.*,
Row_number() over(partition by e.DEPT_NAME Order by e.salary desc) as rownumber_sal,
RANK() over(partition by e.DEPT_NAME Order by e.salary desc) as rank_sal,
DENSE_RANK() over(partition by e.DEPT_NAME Order by e.salary desc) as denserank_sal
from employee e*/
-- lead and lag
-- fetch a query to display if the salary of an employee is higher, lower or equal to the previous employee
/*Select *,
case
when salary>previous_sal then 'higher'
when salary<previous_sal then 'lower'
else 'equal'
end as sal_compare
from(
Select e.*,
lag(salary) over(partition by e.DEPT_NAME Order by e.emp_ID) as previous_sal
from employee e) x*/
-- Similarly using lead function to see how it is different from lag.
Select e.*,
lag(salary) over(partition by e.DEPT_NAME Order by e.emp_ID) as previous_sal,
lead(salary) over(partition by e.DEPT_NAME Order by e.emp_ID) as next_sal
from employee e
To embed this project on your website, copy the following code and paste it into your website's HTML: