Skip to content
Advertisement

merging start and end date cycle dates

I have the below table.

I need to merge dates (exclude rows) when the below occurs.

Criteria:

lead cust_sub_id <> cust_sub_id

lead cust_sub_type = cust_sub_type

lead cust_id = cust_id

lead worker = worker

Final output:

SQL:

I can use listagg to capture the cust_sub_id once I remove the rows but need help removing those rows before I apply the listagg function.

Advertisement

Answer

You can approach this as a gaps-and-islands problem using lag() to determine where an “island” starts and a cumulative sum to assign a grouping number to the island:

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement