select a.serialnum,b.serialnum from tablename a,tablename b
where a.[order]=b.[order]
and b.serialnum =(select min(serialnum) from tablename c where c.serialnum >a.serialnum )
where a.[order]=b.[order]
and b.serialnum =(select min(serialnum) from tablename c where c.serialnum >a.serialnum )
where a.[order] in (select top 1 [order] from t_order b where b.serialnum > a.serialnum order by b.serialnum)
order by serialnum
declare xx,serialnum的类型
yy,serilanum的类型
zz,order的类型
declare cursor 游标名
for select serialnum from 表
open 游标名
fetch 游标名 into xx
while not 游标到记录尾
begin
set yy=xx
fetch 游标名 into xx
if yy=xx then return
end
close 游标
释放游标
把zz设为ouput,读zz.