今天一同事問我以下需求用SQL如何實現(xiàn)
需求:
LWH_TEST表一個SEQ欄位,對應(yīng)的值(不連續(xù)的流水碼)
1,
2,
4,
6,
8
.
.
.
以下SQL可查出缺失的流水號:3,5,7...
select b.SEQ - a.SEQ, b.SEQ, a.SEQ from
( select SEQ , ROWNUM RN from (select SEQ from LWH_TEST order by SEQ) ) a,
( select SEQ , ROWNUM RN from (select SEQ from LWH_TEST order by SEQ) ) b
where a.RN+1 = b.RN
and b.SEQ - a.SEQ > 1
感覺還可以
posted on 2011-02-23 15:55
Ke 閱讀(595)
評論(3) 編輯 收藏 所屬分類:
oracle