发布网友 发布时间:2022-04-13 19:34
共5个回答
懂视网 时间:2022-04-13 23:55
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);
可根据自己的情况自由发挥
,热心网友 时间:2022-04-13 21:03
这个sql应该比较容易,楼主你陷入误区了吧热心网友 时间:2022-04-13 22:21
select t.列1, t.列2, count(t.列2)热心网友 时间:2022-04-13 23:56
SELECT T.a, COUNT(T.a),t.b,COUNT(t.b)热心网友 时间:2022-04-14 01:47
用group by 进行分组