I need to make a small adjustment here and not sure if it can be
done.
In the following, if there is no '001' row, then I only want 1 row for
that order, but when there is 001 i do want that and the next one
according to earliest time.
CREATE VIEW rklib.clspaytp AS Select * from
(
Select x.*,
row_number() over (partition by otord#
order by case ottrnc when '001' then 1 else 2 end
, ottrnd, ottrt
)
as RowN
from rklib.clspaytpp x
) a
where a.RowN in (1,2)