统计数值,如果隔行则算一行

本文通过一个具体的SQL查询案例,展示了如何使用WITH临时表、窗口函数ROW_NUMBER()以及GROUP BY进行复杂的数据分组和排序操作。通过对不同字段的组合使用,实现了特定条件下的数据汇总与展示。

with temp as(
select 1 col1,2 col2 from dual
union all
select 2 col1,2 col2 from dual
union all
select 3 col1,2 col2 from dual
union all
select 4 col1,9 col2 from dual
union all
select 5 col1,9 col2 from dual
union all
select 6 col1,2 col2 from dual
union all
select 7 col1,2 col2 from dual
union all
select 8 col1,3 col2 from dual
)
select COL2,count(*)
from
(
select L.*,
ROW_NUMBER() OVER ( PARTITION BY  COL2  ORDER BY  COL1 DESC ) + COL1 AS GGM
FROM temp L
) A
group by A.COL2,GGM
order by min(A.COL1)

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值