Forum Discussion
Jasmyn1565
Aug 29, 2024Copper Contributor
Condensing Data into a Range
Hello, I am looking to condense data into a range. I have an example below. In the sheet it shows: (All the data is in the same cell) Sally 1 Sally 2 Sally 3 Carl 1 John 1 John 2 Is...
peiyezhu
Aug 30, 2024Bronze Contributor
select * from 带字母序号离散转连续;
create temp table aa2 as
select *,regexp2('(\D+)(\d+)',序号,1) 前缀,regexp2('(\D+)(\d+)',序号,2) 原始 from 带字母序号离散转连续 order by regexp2('(\D+)(\d+)',序号,2) ;
create temp table aa3 as select *,原始-row_number() over (partition by 前缀) 差 from aa2;
create temp table aa as
select *,iif((select count(*) from aa3 a where a.前缀=b.前缀 and a.差=b.差)>2,1,rowid) 计数 from aa3 b;
create temp table bb as select 原始,差,iif( (max(原始)-min(原始)>1),前缀||min(原始)||'-'||前缀||max(原始),前缀||原始) 新序号,前缀 from aa group by 前缀,差,计数;
select group_concat(新序号) from bb group by 前缀;
| 序号 |
| Sally 1 |
| Sally 2 |
| Sally 3 |
| Carl 1 |
| John 1 |
| John 2 |
| group_concat(新序号) |
| Carl 1 |
| John 1,John 2 |
| Sally 1-Sally 3 |