Finding Minimum and Maximum Values for Consecutive Rows with Gaps and Islands
The goal is to extract minimum and maximum values of startt and endd columns for consecutive rows sharing the same act value, while ignoring gaps and islands of rows with different act values.
Solution:
To achieve this, we utilize row numbers to identify consecutive groups of similar rows:
with cte as ( select name, act, rn, startt, endd, row_number() over (partition by name, act order by rn) as act_rn from input ) select name, act, min(startt), max(endd) from cte group by name, act, act_rn - rn;
Explanation:
The above is the detailed content of How to Find Minimum and Maximum Values Across Consecutive Rows with Gaps and Islands?. For more information, please follow other related articles on the PHP Chinese website!