WITH t AS ( SELECT '20120201' dt, 'A' v FROM dual UNION ALL SELECT '20120101', 'B' FROM dual UNION ALL SELECT '20111201', 'B' FROM dual UNION ALL SELECT '20111101', 'A' FROM dual UNION ALL SELECT '20111001', 'B' FROM dual UNION ALL SELECT '20110901', 'A' FROM dual UNION ALL SELECT '20110801', 'B' FROM dual UNION ALL SELECT '20110701', 'B' FROM dual UNION ALL SELECT '20110601', 'A' FROM dual ) SELECT MAX(dt) dt FROM (SELECT dt, v , LEAD(v) OVER(ORDER BY dt DESC) x FROM t ) WHERE v = 'B' AND NVL(x, 'x') != 'B' ;