Wednesday, December 21, 2022

SQL to find the employee who got a salary increase for consecutive 2 years

 DAY 5

#15DAYSSQLCHALLENEGE

----EY INTERVIEW QUESTION----

--Write a SQL to find the employee who got a salary increase for consecutive 2 years 

----------------------------Table creation----------------
--create table EMP_EY
(
emp_name varchar(10),
dep_id int,
salary int,
YEARL DATETIME
);
--DROP TABLE  EMP_EY;
insert into EMP_EY values 
('Siva',1,30000,'2000'),('Siva',1,40000,'2001'),('Siva',1,50000,'2002'),('Arabinda',2,1000,'2010'),
('Arabinda',2,2000,'2011'),('Arabinda',2,3000,'2012'),
('Robert',3,100,'2012'),('Robert',3,102,'2015'),('Robert',3,105,'2017'),
('Sanvi',4,199,'2018'),('Sanvi',4,99,'1990'),('Sanvi',4,9,'1993')
-------------------------------------------------Table creation --END -----------
SELECT * FROM EMP_EY


SELECT E1.*  FROM EMP_EY E1

INNER JOIN EMP_EY E3 ON YEAR (E1.YEARL)=YEAR (E3.YEARL)+1 AND E1.salary > E3.salary

INNER JOIN EMP_EY E4 ON YEAR (E1.YEARL)=YEAR (E4.YEARL)+2 AND E1.salary > E4.salary







No comments:

Post a Comment

"🚀 Delta Lake's Vectorized Delete: The Secret to 10x Faster Data Operations!"

"🚀 Delta Lake's Vectorized Delete: The Secret to 10x Faster Data Operations!" Big news for data engineers! Delta Lake 2.0+ in...