请教一句update语句?
create table test
(
name varchar(20),
type varchar(20)
)
insert into test select 'a1 ', '半挂车 '
insert into test select 'a2 ', '半挂车 '
insert into test select 'a3 ', '半挂车 '
insert into test select 'a4 ', '半挂车 '
insert into test select 'a5 ', '半挂车 '
insert into test select 'a6 ', '半挂车 '
select * from test
/*
写一句update语句,把name列更新为 '1 ', '2 ', '3 '.....依次递增
name type
1 半挂车
2 半挂车
3 半挂车
4 半挂车
5 半挂车
6 半挂车
*/
drop table test
------解决方案--------------------update test set [name]=right([name],len([name])-1)
------解决方案--------------------create table test
(
name varchar(20),
type varchar(20)
)
insert into test select 'a1 ', '半挂车 '
insert into test select 'a2 ', '半挂车 '
insert into test select 'a3 ', '半挂车 '
insert into test select 'a4 ', '半挂车 '
insert into test select 'a5 ', '半挂车 '
insert into test select 'a6 ', '半挂车 '
Update A Set name = (Select Count(*) From test Where name <= A.name) From test A
select * from test