I have following data in one of the table
I would like to distinguished them based on the highlighted record, for example: when I select record based on Foreign_key column and the second record is "Content = Response OR Process_id = 11" then I need to label it as "PROCESS". If the second record is not Content = Response but instead "Content = Initiate OR Process_id = 20" (Foreign_key = 101) then I want to label it "NOT PROCESS".
HINT: activity in this table is created in the Processdate order (ASC).
Can anyone suggest me SQL query, bear in mind I need to execute the query inside CASE due to loads of other JOIN statements.
Analytic functions are your rescue
Here a complete example:
gives