SELECT row_id, p_id, dt,
RANK() OVER (PARTITION BY p_id ORDER BY row_id ASC) AS rank
FROM tab
ORDER BY p_id, row_id ASC;
I want only the record with highest rank per p_id and i also want the rank. Is there a way to do so without putting the above query into a sub-query and selecting the MAX(rank)