zOs/SQL/TECSVSEL

with a (db, ts, pa, stage, unl, err) as
(
  select db, ts, pa, stage, unl, 'refresh older 1 secs'
    from OA1P.TQZ005TECSVUNLOAD
    where stage = 'r' and unlTst < current timestamp - 2 seconds
  union all select db, ts, pa, stage, unl, info
    from OA1P.TQZ005TECSVUNLOAD
    where stage <> 'r' and info <> ''
)
select *
     from a
     order by case when stage = 'r' then 0 else 1 end, db, ts, pa
;x;
select *
    from OA1P.TQZ005TECSVUNLOAD
    where info <> ''
    order by db, ts, pa
;x;
select count(*), err
    from OA1P.TQZ005TECSVUNLOAD
    group by err