应该可以用lag或者lead函数处理,但是我奇怪你的1002帐期数据对应的上一帐期应该使1001帐期有数据才对,你给出的全是null,这个是不是有问题?
你看看下面的应该是不是你要的模式:
SQL> select * from test; MARK NAME
----- --------------------
88 1
84 2SQL>
SQL> select name name1, 1 ,
2 lead(name,1,0)over(partition by rid order by name) name2,
3 lead(,1,0)over(partition by rid order by name) 2 from (
4 select 1 rid,name, from test);NAME1 MARK1 NAME2 MARK2
-------------------- ----- ---------------------------------------- ----------
1 88 2 84
2 84 0 0
你看看下面的应该是不是你要的模式:
SQL> select * from test; MARK NAME
----- --------------------
88 1
84 2SQL>
SQL> select name name1, 1 ,
2 lead(name,1,0)over(partition by rid order by name) name2,
3 lead(,1,0)over(partition by rid order by name) 2 from (
4 select 1 rid,name, from test);NAME1 MARK1 NAME2 MARK2
-------------------- ----- ---------------------------------------- ----------
1 88 2 84
2 84 0 0
解决方案 »
- 怎么查看数据文件的具体内容
- PL/SQL Developer 8.0.2.1505 不停刷新
- 数据的插入问题
- 【求助】高手能否提供DBATools For PL/SQL Developer的无限期试用版???
- 关于SQL效率,请进来看一下!
- 求一基本的SQL语句,在线等。解决后马上结贴。
- oracle 怎么定义自己的数据类型
- 请问哪里有《oracle 9i数据库管理员实用技术指南》和《oracle 9i 数据库管理员高级技术指南》
- 高分相送,实现以下功能的触发器怎样写?
- 高分求解存储过程问题!!!
- 查询语句的优化问题,急,火急!!!
- 我知道Oracle中自增字段要建立sequence,然后取sequence的值。那假设我有100张表的主键都是自增字段,那岂不是要建立100个sequence。
A.*
A.*
A.*
A.*
B.*
B.*
B.*
B.*
from
(
select
(
nvl(A.*)as A.*,
nvl(A.*)as A.*,
nvl(A.*)as A.*,
nvl(A.*)as A.*,
)
form *
union
select
(
nvl(B.*)as B.*,
nvl(B.*)as B.*,
nvl(B.*)as B.*,
nvl(B.*)as B.*,
)
form *)大致的结构就是这样的,你的条件给的不全,没法替你写完,依据结构自己写吧
from
(select process_type,acct_item_type_id,billing_cycle_id,sum(charge) from A where region_id=? group by process_type,acct_item_type_id,billing_cycle_id) b
full outer join
(select process_type,acct_item_type_id,billing_cycle_id,sum(charge) from A where region_id=? group by process_type,acct_item_type_id,billing_cycle_id) c
where b.process_type=c.process_type and b.acct_item_type_id=c.acct_item_type_id
and b.billing_cycle_id=c.billing_cycle_id
注:oracle9i支持outer join
from
(select process_type,acct_item_type_id,billing_cycle_id,sum(charge) from A where region_id=? group by process_type,acct_item_type_id,billing_cycle_id) b
full outer join
(select process_type,acct_item_type_id,billing_cycle_id,sum(charge) from A where region_id=? group by process_type,acct_item_type_id,billing_cycle_id) c
where b.process_type=c.process_type and b.acct_item_type_id=c.acct_item_type_id
and b.billing_cycle_id=c.billing_cycle_id+1