 <p>Do it whit PL/SQL, something like this:</p> <ol> <li>Create the table with data if you don't have it:</li> </ol> <p><a href="https://i.stack.imgur.com/PNo3t.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/PNo3t.png" alt="enter image description here"></a></p> <ol start="2"> <li>Create a temporary function that help with returning the latest flag:</li> </ol> <p><a href="https://i.stack.imgur.com/XI5HK.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/XI5HK.png" alt="enter image description here"></a></p> <ol start="3"> <li>Make a group query that call the temporary function to get the data:</li> </ol> <p><a href="https://i.stack.imgur.com/mt3Cf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mt3Cf.png" alt="enter image description here"></a></p>