更新特定的数字,该数字在mysql中大于3 [英] updating particular numbers in which number greater then 3 in mysql

查看:80
本文介绍了更新特定的数字,该数字在mysql中大于3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好..
我有两列,如
s.no name
1 adi
2杰伊
3 balu
4 bhanu
5迪帕克
6 jhon
7前锋
我需要在其中添加一个人,按字母顺序排列"anu"名称,在ajey和balu之间添加"anu","anu"数将为3,其余所有更新数将以1递增.我需要更新> 3 s.no值
添加系列后将是
1 adi
2杰伊
3 anu
4 balu
5 bhanu
6迪帕克
7 jhon
8前锋
所以在这里我需要更新查询,但我没有尝试过bcoz,我不知道
请任何人帮我
在此先感谢

hi all..
i had two columns like
s.no name
1 adi
2 ajay
3 balu
4 bhanu
5 deepak
6 jhon
7 striker
in which i need to add one person ''anu'' names are in alphabetical order ''anu'' will be added in between ajey and balu ''anu'' number will be 3 and remaining all update numbers will increment with 1 so i need to update >3 s.no values
after adding the series will be
1 adi
2 ajay
3 anu
4 balu
5 bhanu
6 deepak
7 jhon
8 striker
so here i need update query i did''t tried bcoz i dont know
please can any one help me
thanks in advance

推荐答案

这可能对您有所帮助.
This might help you.
declare @intflag int
declare @intstring varchar(40)
declare @intstringb4 varchar(40)
set @intflag=2
set @intstring = (select [name] from table where sno=2)
While (@intflag <=(select max(sno) from table))
begin
print @intflag
set @intstringb4 = (select [name] from table where sno=@intflag+1)
update table set [name]=@intstring where sno=@intflag+1
set @intstring = @intstringb4
set @intflag = @intflag + 1
update table set [name]='anu' where id=@intflag
end


create procedure [dbo].[updatest]
as
begin

update st set sno=sno+1 where sno>=3
insert into st values(3,'anu')
select * from st order by sno
end


您可以尝试为此编写存储过程-单个查询可能不足以完成所有操作此处理.
You could try writing a stored procedure for this - a single query may not be sufficient to do all this processing.


这篇关于更新特定的数字,该数字在mysql中大于3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆