原始表(字段都是数据类型的)
A B c
2012 1 20
2012 2 0
2012 3 50
2012 4 0
2012 5 0
2012 6 0
2012 7 0
2012 8 80
2012 9 0
2012 10 0
2012 11 90
2012 12 0有没有可能使用sql语句是变成这样的结果(最好以试图的形式出现)
A B c
2012 1 20
2012 2 20
2012 3 50
2012 4 50
2012 5 50
2012 6 50
2012 7 50
2012 8 80
2012 9 80
2012 10 80
2012 11 90
2012 12 90不能用存储过程
A B c
2012 1 20
2012 2 0
2012 3 50
2012 4 0
2012 5 0
2012 6 0
2012 7 0
2012 8 80
2012 9 0
2012 10 0
2012 11 90
2012 12 0有没有可能使用sql语句是变成这样的结果(最好以试图的形式出现)
A B c
2012 1 20
2012 2 20
2012 3 50
2012 4 50
2012 5 50
2012 6 50
2012 7 50
2012 8 80
2012 9 80
2012 10 80
2012 11 90
2012 12 90不能用存储过程
解决方案 »
- 请教一个SQL
- RAC安装时碰到"failed to initialieze ocrconfig",后来我修改了问题,并重新运行root.sh成功,还能接着后面的配置助手吗?
- union all后排序速度问题
- 一个表 把某个字段重复值删掉 使这个字段每个值只有一个, sql语句怎么写?
- 以下的要求怎么实现呢
- 多张表的导出~
- 我在linux上装oracle后,怎么显示乱码,更严重的是在什么框中都不能打字啊!!!!
- oracle 8服务启动不了?在线等待!!!
- 如何查找数据库中前十条记录?select top 10 * from table ?
- 如何检查表空间信息
- Oracle Net Configuration Assistant 失败(急!!!!!!)
- 想做一个校验sql合法性的程序,大家提供点思路
select b.a,b.b,case when c<>0 then c else (select sum(c) from view_tst_aaa a where a.b<=b.b and a.b>=(select max(c.b) from view_tst_aaa c where c.c>0 and c.b<=b.b)) end
from view_tst_aaa b
create table T
(
A VARCHAR2(4),
B INTEGER,
C INTEGER
)
;
insert into T (A, B, C)
values ('2012', 1, 20);
insert into T (A, B, C)
values ('2012', 2, 0);
insert into T (A, B, C)
values ('2012', 3, 50);
insert into T (A, B, C)
values ('2012', 4, 0);
insert into T (A, B, C)
values ('2012', 5, 0);
insert into T (A, B, C)
values ('2012', 6, 0);
insert into T (A, B, C)
values ('2012', 7, 0);
insert into T (A, B, C)
values ('2012', 8, 80);
insert into T (A, B, C)
values ('2012', 9, 0);
insert into T (A, B, C)
values ('2012', 10, 0);
insert into T (A, B, C)
values ('2012', 11, 90);
insert into T (A, B, C)
values ('2012', 12, 0);
commit;select t.a,t.b,t1.c
from t,
(select a, b, lead(b, 1) over(order by a, b) r, c from t where c <> 0) t1
where t.b >= t1.b
and (t.b < t1.r or t1.r is null)A B C
---- --------------------------------------- ---------------------------------------
2012 1 20
2012 2 20
2012 3 50
2012 4 50
2012 5 50
2012 6 50
2012 7 50
2012 8 80
2012 9 80
2012 10 80
2012 11 90
2012 12 90
12 rows selected
from tab t
SELECT t.*,
nvl(last_value(nullif(c, 0) ignore NULLS) over(ORDER BY b), 0) a1
FROM t;
A B C A1
---- --------------------------------------- --------------------------------------- ----------
2012 1 20 20
2012 2 0 20
2012 3 50 50
2012 4 0 50
2012 5 0 50
2012 6 0 50
2012 7 0 50
2012 8 80 80
2012 9 0 80
2012 10 0 80
2012 11 90 90
2012 12 0 90
12 rows selected
今天看到一个更简单的方法