SELECT STALENESS, 
       OSIZE, OBJ#, 
       TYPE#, 
       ROW_NUMBER() OVER (PARTITION BY BO# ORDER BY STALENESS, OSIZE, OBJ#),
       CASE WHEN ROW_NUMBER() OVER (PARTITION BY BO# ORDER BY STALENESS, OSIZE, OBJ#) = 1 THEN 64 ELSE 0 END + 
       CASE WHEN ROW_NUMBER() OVER (PARTITION BY (SELECT TCP0.BO# FROM TABCOMPART$ TCP0 WHERE TCP0.OBJ#=ST0.BO#) ORDER BY STALENESS, OSIZE, OBJ#) = 1 THEN 32 
       ELSE 0 END AFLAGS, 
       0 STATUS, 
       :B5 SID, 
       :B4 SERIAL#, PART#, BO#, LOC_STALE_PCT 
FROM 
A