紧急求助! 谢谢了!

linzhisong 2003-04-30 09:16:01
我现在有个表
id name num
1 1 1
2 2 2
3 3 3
4 4 4
5 5 5

现在有一个变量@i
如果@i=1
id name num
1 1 2
2 2 3
3 3 4
4 4 5
5 5
如果@i=2
id name num
1 1 3
2 2 4
3 3 5
4 4
5 5

怎么实现?
...全文
43 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
lizongqi 2003-04-30
  • 打赏
  • 举报
回复
到此一游
linzhisong 2003-04-30
  • 打赏
  • 举报
回复
谢谢!

揭帖!
SophiaWang 2003-04-30
  • 打赏
  • 举报
回复
alter table sub add idd int identity
go

declare @i int
set @i=1

select id,name,(
select num from sub b
where a.idd = b.idd - @i) num from sub a

alter table sub drop column idd
joygxd 2003-04-30
  • 打赏
  • 举报
回复
select a.id,a.name,(case when a.newid=b.newid then (select a.num from a where a.newid=a.newid+1) end )as num
from (select identity(int,1,1) newid,* into #temp from table) a,(select identity(int,1,1) newid,* into #temp from table) b
where a.id=b.id
linzhisong 2003-04-30
  • 打赏
  • 举报
回复
谢谢! 不好意思,我数据给错了 !
SophiaWang 2003-04-30
  • 打赏
  • 举报
回复
select id,name,case when (num+@i)>5 then null else num+@i end num from tablename
linzhisong 2003-04-30
  • 打赏
  • 举报
回复
id name num

asd 34 3434
3sd1 234 grr
fs 343 tt
sd 343 66
asd 343 fff
linzhisong 2003-04-30
  • 打赏
  • 举报
回复
谢谢! 晕,我给的数据怎么就这么巧合!
black_snail 2003-04-30
  • 打赏
  • 举报
回复
select a.id,a.name ,b.num
from t1 a,t1 b
where (a.id + @i) = b.id(+)
pengdali 2003-04-30
  • 打赏
  • 举报
回复
--如果你要修改:

create table #a(id int,name int,num int)
insert #a values(1, 1, 1)
insert #a values(2, 2 ,2)
insert #a values(3 , 3 , 3)
insert #a values(4 , 4 , 4)
insert #a values(5 , 5, 5)

declare @i int

set @i=2

update #a set num=case when num+@i<=5 then num+@i end

select * from #a
go
drop table #a
linzhisong 2003-04-30
  • 打赏
  • 举报
回复
就是等1的时候 把后一笔的num值给前一笔。

以此类推!
stone_lin 2003-04-30
  • 打赏
  • 举报
回复
create function funGetValue(@id int,@i int)
returns int
as
declare @v int
Select @v=num from table where id=@id + @i
return @v


select id,name,funGetValue(id,@i) from table
pengdali 2003-04-30
  • 打赏
  • 举报
回复
create table #a(id int,name int,num int)
insert #a values(1, 1, 1)
insert #a values(2, 2 ,2)
insert #a values(3 , 3 , 3)
insert #a values(4 , 4 , 4)
insert #a values(5 , 5, 5)

declare @i int

set @i=2


select id,name,case when num+@i<=5 then num+@i end num from #a

go
drop table #a
voyager 2003-04-30
  • 打赏
  • 举报
回复
说清楚一点?
1,项目功能:     系统总体上划分为五个模块:接处警模块、预案管理模块、事件处置模块、资源管理模块、案例管理模块。具体业务流程如下:(1)根据突发疾控事件的级别和紧急情况,级别较低的突发疾控事件由接处警模块处置,级别较高或较为紧急的事件由事件处置模块处置。(2)当突发疾控事件发生时,依据接警员提交的事件信息调用相应的预案,并完善相应的信息,包括资源的配置和指定相关责任单位。(3)接受到任务的相关责任单位根据任务内容和实际情况进行突发疾控事件的处置。(4)任务的相关责任单位在处置过程中将事件处置的进展情况及时的进行反馈,跟踪事件处置的情况。(5)事件处置相关单位根据事件反馈情况合理调整任务,保证事件处置的准确性和效率。(6)当突发疾控事件得到控制或者解除紧急状态后,可以结案,事件处置的所有工作结束后,进入案例管理模块。(7)案例管理对突发疾控事件应急管理系统处置的所有重大或特别重大的事件的处置过程以及基本信息进行记录,便于统计和查询。(8)领导和专家可以对案例和事件处置报告进行评估和总结,以便完善预案模板的管理,提高处置相似或者相同突发疾控事件的效率。     适合做毕业设计参考项目。2,涉及技术:SSM框架,Tomcat3,开发环境:IDEA,MySQL数据库4,讲解方式:从环境安装,项目搭建,以及项目介绍等进行讲解5,包含资料:项目源码(含数据库文件),环境安装包,项目文档。

22,209

社区成员

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

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