I'm trying an SQL query in Teradata to find the gaps and group the duration. I have a dataset with duration gap, I’m trying to find the gap and group them. When I use the min and max dates shows different results for long gap in terms of duration.
Duration is mentioned in YearMonth with activity info. I tried interval with rows bounding as well but shows a wrong results in case of duration gap is longer period. Could you please help me to have the expected results please?
expected output results :

