close
LV超3A名牌購物網
SQL顺序列找出断号
href="/question/#'" class='liveword' title='方法'>方法一:
select (select max(id)+1 from 你的資料表 where id<a.id) as beginId,(id-1) as endId
from 你的資料表 a
where
a.id>(select max(id)+1 from 你的資料表 where id<a.id)
方法二:
select beginId,(select min(id)-1 from 你的資料表 where id > beginId) as endId
from (
select id+1 as beginId from 你的資料表 where id+1 not in (select id from 你的資料表) and id < (select max(id) from 你的資料表)
) as t
**********************************************************
但上面的缺點是:
如果您是一開始的 id編號有缺乏,就找不出來。
例如從一號開始編號。
但您把 1 / 2 / 3三個編號刪除了,他是呈現不出來的
只能從 4號開始,把遺失的、已刪除的 id流水號給呈現出來。
**********************************************
ASP.NET 專題實務與教學網站
參考資料
LV超3A名牌購物網
全站熱搜