add batch remove batch split batch comment selection show hidden batches hide batch highlight batch
db<>fiddle
donate feedback about
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
Create Table table_name(Student VARCHAR(50), Time_ TIME);

Insert Into table_name Values('A','5:00'),
('B','7:00'),
('A','8:00'),
('C','9:00'),
('D','10:00'),
('E','11:00'),
('D','12:00');
Records: 7  Duplicates: 0  Warnings: 0
SELECT Student, Time_,
SUM(flag) OVER (ORDER BY Time_) AS expected_count
FROM
(
SELECT *,
CASE
WHEN EXISTS(SELECT 1 FROM table_name D WHERE D.Student = T.Student AND D.Time_<T.Time_)
THEN 0 ELSE 1
END AS flag
FROM table_name T
) D
ORDER BY Time_
Student Time_ expected_count
A 05:00:00 1
B 07:00:00 2
A 08:00:00 2
C 09:00:00 3
D 10:00:00 4
E 11:00:00 5
D 12:00:00 5