Oracle 按相同数据连续统计 CREATE TABLE TEST(ID NUMBER(20),val NUMBER(20))INSERT INTO TEST VALUES(1,5);INSERT INTO TEST V
Oracle 按相同数据连续统计
CREATE TABLE TEST(
ID NUMBER(20),
val NUMBER(20)
)
INSERT INTO TEST VALUES(1,5);
INSERT INTO TEST VALUES(2,10);
INSERT INTO TEST VALUES(3,10);
INSERT INTO TEST VALUES(4,10);
INSERT INTO TEST VALUES(5,6);
INSERT INTO TEST VALUES(6,6);
INSERT INTO TEST VALUES(7,10);
INSERT INTO TEST VALUES(8,10);
SELECT val,COUNT(*) FROM
(
SELECT ID,val,
row_number() OVER(ORDER BY ID)-row_number() OVER(PARTITION BY val ORDER BY ID) x
FROM TEST
)
GROUP BY val,x
ORDER BY MIN(ID);
可根据自己的情况自由发挥
, 本条技术文章来源于互联网,如果无意侵犯您的权益请点击此处反馈版权投诉 本文系统来源:php中文网