I am trying to If there is a previous service_key exist in Start_service table group by reg_key ( I sorted by service_key and assigned a row id group by reg_key ) ,set Action column as 'T' in Start_Service table If there is a next service_key from service_key in End_service table exist in Start_service table group by reg_key ,set Action a column as 'T' in End_service tableFor example, service_key = 234 in start_service table doesn’t have a previous service_key in Start_service table , so it doesn’t qualify for Action = 'T'Next serviceKey = 237 in start_service table has a previous service_key = 234, so it qualify for Action = 'T'Service_key = 234 in End_service table has a next service_key in Start_Service table., so it qualify for Action = 'T'Service_key = 347 in End_service table doesn’t have a next serviceKey in Start_service table, so it does NOT qualify for Action =T'Start_service reg_key service_key Rowid 1001 234 1 1001 237 2 1001 238 3 1003 345 1 1003 347 2 1009 657 1 1011 777 1 1011 888 2 1011 999 3 1044 111 11044 113 2End_serviceReg_key service_key RowId 1001 234 1 1003 347 1 1009 657 11011 888 11011 999 21044 111 11044 113 2
resultStart service reg_key service_key Rowid Action 1001 234 1 1001 237 2 T 1001 238 3 T 1003 345 1 1003 347 2 T 1009 657 1 1011 777 1 1011 888 2 T 1011 999 3 T1044 111 11044 113 2 TEnd serviceReg_key service_key RowId Action1001 234 1 T1003 347 1 1009 657 1 1011 888 1 T1044 111 1 T1044 113 2