Click here to Skip to main content
15,904,877 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
SQL
table Employee
EmpId
Name
MonthlySalary
DateofJoining

Suggest  a sql server query to find out the employee details whose having salary greater than their yers of experiance
Posted
Updated 13-Jun-14 4:26am
v2
Comments
DamithSL 13-Jun-14 10:18am    
What!
is there any employee who get less than 100 salary in your company?
Telstra 13-Jun-14 10:22am    
LOL!
do you have idea how to find this answer. It is asked to me today in interview.
Wrong. :)
goathik 13-Jun-14 10:30am    
are you trying to troll us with that troll they did to you on that interview, mister? ;)
goathik 13-Jun-14 10:34am    
suppose i have 3 years of experience, the select must return me, only if i earn 3+ dollars? It really makes no sense... or perhaps... you wanted to ask for the employee that earns the better salary, even tho he worked there for less time? suppose Victor works there for 3 years and he already gets $5000, although Alex still gets $2000, even he is there for 10 years. So that select should show Victor first, then Alex?

Try something along the lines of
SQL
SELECT * FROM Employee WHERE MonthlySalary > DATEDIFF(yy, DateofJoining, GETDATE())
But to be honest, if you can't work that out for yourself, you are applying for the wrong jobs...
 
Share this answer
 
Quote:
do you have idea how to find this answer. It is asked to me today in interview.
If you think practically, it is a wrong question.

But logically, it is asked to make you write the query which would check the Salary by comparing the Year difference between the DateofJoining and Current Date.

Demo - [Demo] Find Employees having Salary more than their Experience[^]
 
Share this answer
 
v2
 
Share this answer
 
Instead OF DATEDIFF We Can Use Now Directly YEAR And MONTH function Available..
..
Thanks
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900