Question

I think this is easy to accomplish using OLAP functions, but I still haven't found the winning combination.

My table has the following fields:

  • request_id
  • corresp_id
  • corresp_type
  • corresp_status
  • create_ts

For every request I have multiple correspondences of different kind and statuses.

I need to find the requests where the first correspondence, has corresp_type=3 and corresp_status=4

Was it helpful?

Solution

Find the first row for each request based on create_ts and check if it has corresp_type=3 and corresp_status=4

select request_id
from tab
qualify
   row_number() 
   over (partition by request_id
         order by create_ts) = 1 
and corresp_type=3 
and corresp_status=4
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top