Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help finding IDs with FIVE CONSECUTIVE YEARS of Service 1

Status
Not open for further replies.

SirWaldizmo

Programmer
Mar 4, 2002
9
US
Hello,
I have a table of two columns one is ID and the second is Year_Of_Service. IDs are duplicated in this table where there are more than one year of service.

Does anyone know of a logic in sql that can find all the IDs that have at least 5 consecutive years of Service.

Any suggestions will be appreciated.
SirWaldizmo
 
if we have
Jim 1991
Larry 1991
Jim 1992
Jim 1993
Jim 1994
Larry 1994
Jim 1995
Jim 1996

as records


then
select distinct a.ID
from mytable a, mytable b, mytable c, mytable d, mytable e
where b.Year_of_Service = a.Year_of_Service + 1
and c.Year_of_Service = a.Year_of_Service + 2
and d.Year_of_Service = a.Year_of_Service + 3
and e.Year_of_Service = a.Year_of_Service + 4;

I tried to remain child-like, all I acheived was childish.
 
oops

and a.ID = b.ID
and a.ID = c.ID
and a.ID = d.ID
and a.ID = e.ID;

sorry I tried to remain child-like, all I acheived was childish.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top