I have this table :
I want to find minimum date_time value for each bunch of colored record, that is, the result of the table will be this table.
Which SQL command is needed?
I have this table :
I want to find minimum date_time value for each bunch of colored record, that is, the result of the table will be this table.
Which SQL command is needed?
This is sort-of a gaps-and-islands problem. But the simplest way to think of it is as a simple lag()
:
select t.*
from (select t.*,
lag(t.strand1) over (order by t.date_time) as prev_strand1
from t
) t
where prev_strand1 is null or prev_strand1 <> strand1;
If you want to find minimum of date_time value for each whatever value of Strand1
select Strand1, min(DATE_TIME) from mytable where Strand1 = whatever group by Strand1