求SQL语句或者存储过程,不连续最大值问题,急!

hesyer 2005-08-12 09:42:48
1,aaa,1
2,aaa,2
3,bbb,1
4,bbb,2
5,aaa,3
6,aaa,4
7,aaa,5


---------
1,aaa,2
4,bbb,2
7,aaa,5
...全文
103 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
zlp321002 2005-08-12
  • 打赏
  • 举报
回复
-- libin_ftsafe(子陌红尘) 倒还真快啊!服!
zlp321002 2005-08-12
  • 打赏
  • 举报
回复
--没看出什么规律,这个是一个字段?还是三个字段??
--不连续最大值问题,是什么意思?能不能解释下!
--看看楼下的,怎么解决!
子陌红尘 2005-08-12
  • 打赏
  • 举报
回复
--生成测试数据
create table #t(id int,name varchar(4),num int)
insert into #t select 1,'aaa',1
insert into #t select 2,'aaa',2
insert into #t select 3,'bbb',1
insert into #t select 4,'bbb',2
insert into #t select 5,'aaa',3
insert into #t select 6,'aaa',4
insert into #t select 7,'aaa',5


--执行查询
select
a.*
from
#t a
where
not exists(select 1 from #t where id=a.id+1 and num=a.num+1 and name=a.name)


--输出查询结果
ID NAME NUM
-- ---- ---
2 aaa 2
4 bbb 2
7 aaa 5
子陌红尘 2005-08-12
  • 打赏
  • 举报
回复
create table #t(id int,name varchar(4),num int)
insert into #t select 1,'aaa',1
insert into #t select 2,'aaa',2
insert into #t select 3,'bbb',1
insert into #t select 4,'bbb',2
insert into #t select 5,'aaa',3
insert into #t select 6,'aaa',4
insert into #t select 7,'aaa',5

select
a.*
from
#t a
where
not exists(select 1 from #t where id=a.id+1 and num=a.num+1 and name=a.name)

34,590

社区成员

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

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