Row number, case and greater than in sql for expired rows, max date value need to be processed as Rownum = 1