日期:2014-05-17 浏览次数:20882 次
Connected to Oracle Database 11g Enterprise Edition Release 11.2.0.3.0
Connected as RCOTRPR1
SQL> select * from idcsdn;
NO ID BED DAT
---------- ---------- ---------- -----------
1 11111 A-1 1/4/2011 11
2 11111 A-2 2/4/2011 11
3 11111 A-3 3/4/2011 11
4 11111 A-4 4/4/2011 11
5 11112 A-4 6/4/2011 11
6 11112 A-5 7/4/2011 11
7 11112 A-6 8/4/2011 11
7 rows selected
SQL>
SQL> SELECT no, id, bed, next_dat - dat
2 FROM (SELECT no, id, bed, dat, lead(dat, 1) over(PARTITION BY id ORDER BY bed) AS next_dat FROM idcsdn)
3 WHERE next_dat IS NOT NULL;
NO ID BED NEXT_DAT-DAT
---------- ---------- ----------&nb