一个痛苦的问题!在线等!

guo8216 2006-10-29 04:11:17
物料 序号 工序
001 1 木工
001 2 木工
001 3 打磨
001 4 木工
001 5 打磨
001 6 五金
请问我怎么对上面这个表进行分类汇总得到下面的结果:
物料 序号 工序
001 3 木工
001 4 木工


...全文
154 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
DavidNoWay 2006-10-29
  • 打赏
  • 举报
回复
跑过,学习
xyxfly 2006-10-29
  • 打赏
  • 举报
回复
......
xyxfly 2006-10-29
  • 打赏
  • 举报
回复
create table test(
物料 varchar(10), 序号 int, 工序 varchar(10))
insert test
select '001', 1, '木工' union
select '001', 2, '木工' union
select '001', 3, '打磨' union
select '001', 4, '木工' union
select '001', 5, '打磨' union
select '001', 6, '五金'



select a.* from test a where not exists(select 1 from test where 物料=a.物料 and 工序=a.工序 and 序号=a.序号+1)
and a.[工序]='木工'


drop table test
-----------------
物料 序号 工序
---------- ----------- ----------
001 2 木工
001 4 木工

StarRains 2006-10-29
  • 打赏
  • 举报
回复
--测试数据:
declare @t table (物料 varchar(10), 序号 int, 工序 varchar(10))
insert into @t
select '001', 1, '木工'
union all
select '001', 2, '木工'
union all
select '001', 3, '打磨'
union all
select '001', 4, '木工'
union all
select '001', 5, '打磨'
union all
select '001', 6, '五金'


--查询:
select * from @t a where not exists(select [序号] from @t b where b.[序号] =a.[序号]+1 and b.工序=a.工序 ) and [工序]='木工'

guo8216 2006-10-29
  • 打赏
  • 举报
回复
不要了,我要找的是相同工序,序号不间断最大的一个序号的那一条!
xyxfly 2006-10-29
  • 打赏
  • 举报
回复
001 1 木工


这个呢?不要了?
guo8216 2006-10-29
  • 打赏
  • 举报
回复
不好意思搞错了应该是下面的结果
物料 序号 工序
001 2 木工
001 4 木工
xyxfly 2006-10-29
  • 打赏
  • 举报
回复
???
怎么来的?

22,210

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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