目录
0 需求描述
如下图所示,按照定义的规则进行数据变换
注意:b中的数值只有0和1
1 数据准备
with data as(
select 2010 a,0 b union all
select 2011 a,1 b union all
select 2012 a,0 b union all
select 2013 a,1 b union all
select 2014 a,0 b union all
select 2015 a,0 b union all
select 2016 a,1 b union all
select 2017 a,0 b union all
select 2018 a,0 b union all
select 2019 a,0 b union all
select 2020 a,1 b union all
select 2021 a,1 b union all
select 2022 a,0 b union all
select 2023 a,1 b union all
select 2024 a,0 b
)
2 数据分析
问题分析:根据规则,只要b中相邻三个值中有1即可合并。
该规则描述了两个问题点:
(1)相邻问题。相邻三个值如何表
标签:数据分析,进阶,union,规则,相邻,SQL,断点,select,描述 From: https://blog.csdn.net/godlovedaniel/article/details/141063892