----创建测试数据
declare @ta table(id int,colX int)
declare @tb table(id int,colX int)
insert @ta
select 1,1 union all
select 2,1 union all
select 3,1 union all
select 4,1
insert @tb
select 1,1 union all
select 1,1 union all
select 1,1 union all
select 2,1 union all
select 2,1 union all
select 3,1 ----更新
update a set colX = b.colX from @ta as a
inner join (select id,isnull(sum(colX),0) as colX from @tb group by id) b
on a.id = b.id
----查看
select * from @ta/*结果
id colX
1 3
2 2
3 1
4 1
*/
declare @ta table(id int,colX int)
declare @tb table(id int,colX int)
insert @ta
select 1,1 union all
select 2,1 union all
select 3,1 union all
select 4,1
insert @tb
select 1,1 union all
select 1,1 union all
select 1,1 union all
select 2,1 union all
select 2,1 union all
select 3,1 ----更新
update a set colX = b.colX from @ta as a
inner join (select id,isnull(sum(colX),0) as colX from @tb group by id) b
on a.id = b.id
----查看
select * from @ta/*结果
id colX
1 3
2 2
3 1
4 1
*/
解决方案 »
- 怎么能看出SQLserver 是不是企业版的。
- ACCESS2003 下这样的 SQL 语句,执行为什么出错呢? 急呀,HELP!!!!!!
- 关于视图 索引
- 40分在线求助大家,类似QQ的最低5位号码随时生成并抽取显示的问题?
- 用触发器来做
- 安装sql2005出现的问题 帮着看看
- 请各位高手赐教,疑难检索效率问题数据量上10万!
- sql查询,有点难度,帮忙一下下!!
- sql2000数据库如何打包
- 有没有什么办法或工具查看MS SQL SERVER中日志文件的语句?如insert, update,delete...
- .net面试中遇到的一个问题,希望那位高手能帮忙解决!!!
- 大虾请帮忙:如何判断表中的数据错误。
果然利害,3Q