Query to get employees list with whose experience is multiple of 5

I have a query where I want to find the list of employees whose years of experience is multiple of 5, i.e whose experience is above 5 years, above 10 years, above 15 years etc. Employees who crossed 6 years, list should not display, It should display only employee experience with 5,10,15 years.and so on.

table columns
employee id, name, dob, join date.

Can Please anyone help me to get the result

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

You can get the difference between todays date and the join_date in years and take all those having a multiple of 5 using the modulo operator

select *
from employees
where timestampdiff(YEAR, join_date, now()) % 5 = 0

SQLFiddle demo


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x