我总结过这样的如何处理,你搜索下吧,给你个例子!
[PHP]sql
SQL> With x As
2(
3Select '002' eba002,'001' eba083,'100' eba084 From dual
4Union
5Select '002','101','200' From dual
6Union
7Select '002','201','250' From dual
8Union
9Select '002','301','400' From dual
10Union
11Select '003','001','200' From dual
12Union
13Select '003','300','400' From dual
14)
15Select Distinct eba002,decode(a,1,Min(eba083) over (Partition By eba002,a),eba083),
16decode(a,1,max(eba084) over (Partition By eba002,a),eba084) From (
17Select eba002,eba083,eba084,
18eba083 - lag(eba084,1,eba083-1) over (Partition By eba002 Order By eba083) a
19From x
20) order by 1,2
21/
EBA002 DECODE(A,1,MIN(EBA083)OVER(PAR DECODE(A,1,MAX(EBA084)OVER(PAR
------ ------------------------------ ------------------------------
002001
250
002301
400
003001
200
003300
400
SQL>
[/PHP]
|