首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

sql 分类找最大的并更新,该如何处理

2012-05-28 
sql 分类找最大的并更新id wc wd1a122a133fdf 124f3d 1352214要更新成这样id wc wd3fdf +1 1243df +1 1352

sql 分类找最大的并更新
id wc wd
1 a 12
2 a 13
3 fdf 12
4 f3d 13
5 22 14
要更新成这样
id wc wd


3 fdf +1 12
4 3df +1 13
5 22+1 14

update 不让我使用update table set wc=wc+1 where id=(select max(id) from table group by wd)

[解决办法]

SQL code
declare @T table (id int,wc varchar(10),wd int)insert into @Tselect 1,'a',12 union allselect 2,'a',13 union allselect 3,'fdf',12 union allselect 4,'f3d',13 union allselect 5,'22',14update @T set wc=wc+'+1' from @T twhere id=(select max(id) from @T where wd=t.wd)select * from @T/*id          wc         wd----------- ---------- -----------1           a          122           a          133           fdf+1      124           f3d+1      135           22+1       14*/
[解决办法]
Mysql的跑这来干啥啊?语法不一样,你去相应的板块问问嘛
探讨

引用:

SQL code

declare @T table (id int,wc varchar(10),wd int)
insert into @T
select 1,'a',12 union all
select 2,'a',13 union all
select 3,'fdf',12 union all
select 4,'f3d',13 union……

热点排行