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

来源:互联网 发布:好用的面膜推荐知乎 编辑:程序博客网 时间:2024/05/16 12:55

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)

原创粉丝点击