--try;select a.单位编号,a.收入-b.收入 差 from
(
select rownum no,单位编号,收入 from tb
) a,
(
select rownum no,单位编号,收入 from (select '000' 单位编号,0 收入 from dual union all
select 单位编号,收入 from tb)
) b
where a.no=b.no;
(
select rownum no,单位编号,收入 from tb
) a,
(
select rownum no,单位编号,收入 from (select '000' 单位编号,0 收入 from dual union all
select 单位编号,收入 from tb)
) b
where a.no=b.no;
---- -----------
0001 5000
0002 6000
0003 5600
0004 4000
0004 3000
0004 7000
0004 45007 rows selectedselect no,fee from tb where rownum<2
union
select a.no,fee1-fee2 from
(
select no,fee fee1,rownum id1 from tb order by rownum desc
)a,
(
select no,fee fee2,rownum id2 from
(
select no,fee from tb where rownum<(select count(*) from tb)
) order by rownum desc
)b
where a.id1=b.id2+1
NO FEE
---- ----------
0001 5000
0002 1000
0003 -400
0004 -1600
0005 -1000
0006 4000
0007 -25007 rows selected
可以互相交流