select b.type, min(b.ltime) ltime
from (select a.*,
cast(row_number() over (partition by a.type order by a.ltime) as signed) a,
cast(row_number() over (order by a.ltime) as signed) b,
cast(row_number() over (partition by a.type order by a.ltime) as signed) -
cast(row_number() over (order by a.ltime) as signed) rn
from f0323 a) b
group by b.type, b.rn
order by 2
SELECT type, ltime
FROM (SELECT *, RANK() over ( PARTITION BY (mn - rn) ORDER BY ltime ) sm
FROM (SELECT *, ROW_NUMBER() over ( ORDER BY ltime ) mn, ROW_NUMBER() over ( PARTITION BY type ORDER BY ltime ) rn
FROM f0323) t) n
WHERE sm = 1
ORDER BY ltime