Date: Nov 24, 2012 1:07 PM
Author: Rahat
Subject: Conditional Maximum

I have 3 columns in my database:

ID Year Tenure
12 1992 1
12 1993 2
12 1994 3
12 1995 4
225 2001 1
225 2002 2
225 2003 3
225 2004 4
225 2005 5
225 2006 6
3045 2009 1
3045 2010 2
3045 2011 3


I want to keep IDs with a tenure >=5 years. For that matter I want to create a 4th column containing "Maximum Tenure" against each id such that:

ID Year Tenure MaxTenure
12 1992 1 4
12 1993 2 4
12 1994 3 4
12 1995 4 4
225 2001 1 6
225 2002 2 6
225 2003 3 6
225 2004 4 6
225 2005 5 6
225 2006 6 6
3045 2009 1 3
3045 2010 2 3
3045 2011 3 3

How can I do it? Please help.