Please help me how to write code below one in Oracle DB or Snowflake DB
MIN(PX_ID) OVER(ORDER BY NM, TBKY DESC RESET WHEN TBKY = 'B')
QUALIFY TBKY = 'A'
You need to apply nested OLAP functions to create a dynamic partition first, see this thread.
Btw, it might be possible to implement this logic using a single LAST_VALUE...