You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

基于Hive SQL查找各id分组下最长连续rowid序列的起止点

基于Hive SQL查找按id分组下最长连续rowid序列的起止点

示例数据集

idrowidstatus
112
121
131
141
152
161
171
182
211
221
231
241
311
322
331
341
351

其中rowid按id自增,需查找各id分组内最长连续rowid序列的起止rowid。

预期输出

idstart_idend_id
124
214
335

更新:起止点查找方法

已找到查找起止点的方法,SQL代码如下:

-- 查找结束点
select * from (select * from tbl where status = 1) t1 
left join (select * from tbl where status = 1) t2 on t1.id = t2.id and t1.rowid = t2.rowid + 1
where t2.rowid is null
;
-- 查找起始点
select * from (select * from tbl where status = 1) t1 
left join (select * from tbl where status = 1) t2 on t1.id = t2.id and t1.rowid = t2.rowid - 1
where t2.rowid is null
;

内容的提问来源于stack exchange,提问作者l0o0

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.18 19:05:00