sql - Update value for flag column -
i want create stored procedure updates value current flag y or n comparing values of c1 , c2 , set recent 1 y , older n. in result set below, row 1 , 2 have same values c2 , c2, want set current flag recent y , older n. row 3 in below result set not have duplicate want y.
10 12 9 1985-06-10 null 10 12 60 2015-09-10 null 3 5 23 2001-09-10 null 1 1 96 2010-09-10 null 1 1 71 2016-09-10 null
you can in standard sql using correlated subquery:
update t set flag = (case when date = (select max(date) t t2 t2.c1 = t.c1 , t2.c2 = t.c1) 'y' else 'n' end);
specific databases might have alternative methods, should work in database.
Comments
Post a Comment