散分:一个特简单查询SQL的几种写法
CREATE TABLE mytable(ID INT,VALUE NUMBER(6));
INSERT INTO mytable VALUES(1,10);
INSERT INTO mytable VALUES(2,20);
INSERT INTO mytable VALUES(3,15);
110
220
315
结果:
11010
31545
22040
你会几种?
CREATE TABLE mytable(ID INT,VALUE NUMBER(6));
INSERT INTO mytable VALUES(1,10);
INSERT INTO mytable VALUES(2,20);
INSERT INTO mytable VALUES(3,15);
SELECT * FROM mytable;
SELECT a.id,a.value,SUM(nvl(a."VALUE",0))
FROM mytable A
JOIN mytable b ON b.id<=a.id
GROUP BY a.id,a.value
SELECT ID,VALUE,SUM(VALUE) OVER(ORDER BY ID) FROM mytable;
SELECT ID,value+LAG(VALUE,1,0) OVER(ORDER BY ID) FROM mytable