有两个表
a表
sp_id the_num
1001 5
1002 10
b表
sp_id num
1001 2
1002 1
1002 6
从a表加上b表中对应的数量,以sp_id对应,我用
update a set the_num=a.the_num + b.num from a,b where a.sp_id = b.sp_id
执行以后,对于a表中的1002,怎么只是10+1=11呢?而不是10+1+6=17.请求解。
a表
sp_id the_num
1001 5
1002 10
b表
sp_id num
1001 2
1002 1
1002 6
从a表加上b表中对应的数量,以sp_id对应,我用
update a set the_num=a.the_num + b.num from a,b where a.sp_id = b.sp_id
执行以后,对于a表中的1002,怎么只是10+1=11呢?而不是10+1+6=17.请求解。
解决方案 »
- 新手求助!!!!!!!!
- 存储过程问题 求解insert exec不能嵌套情况下的替代方案
- 一个语句把多列值连接成一个字符串行的问题?
- 按日期Select,Group by出现问题,请教!!!
- 关于MSDE的小问题
- 请教:读取日期之后,日期发生改变。是什么原因造成的??
- 查询学过“001”并且也学过编号“002”课程的同学的学号、姓名
- 数据复制的简单问题(在现等待)
- Sql Server中,使用select top 10 no,name from table语句(no为新增字段),使no按顺序存放1,2,3-10
- 大家请帮帮忙,我这存储过程语法错在那里
- SQL 取数值小数后两位,但不四舍五入。
- 问一个非常菜的问题啊
from a,(select sp_id,sum(num) as num from b group by sp_id) as b
where a.sp_id = b.sp_id
a
set
the_num=a.the_num + b.num
from
a,
(select sp_id,sum(num) as num from b group by sp_id) as b
where
a.sp_id = b.sp_id
sp_id the_sum sp_id num
1001 5 1001 2
1002 10 1002 1
1002 10 1002 6
...
然后再按WHERE进行UPDATE,所以不会出现你想要的效果