请问如何比较一个表中,下一条数据是否和上一条数据相同,如果相同,我要得到这一条的序号

otuotu 2002-04-20 02:10:31
假设表中只有两个字段
serialnum 和 order
我想返回紧挨着的两条记录order相同的serialnum
...全文
48 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
otuotu 2002-04-20
  • 打赏
  • 举报
回复
谢谢关注
liu800323 2002-04-20
  • 打赏
  • 举报
回复

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.
bluepower2008 2002-04-20
  • 打赏
  • 举报
回复
select serialnum from t_order a
where a.[order] in (select top 1 [order] from t_order b where b.serialnum > a.serialnum order by b.serialnum)
order by serialnum
Yang_ 2002-04-20
  • 打赏
  • 举报
回复
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 )

34,575

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧