如何将两个单元格值相加 [英] How to add two cell values

查看:100
本文介绍了如何将两个单元格值相加的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家需要紧急帮助!我有2个表,这些表包含一些值

hi guys need urgent help!! i have 2 tables and those tables contains some values

create table PollingBooth_A(
party_id varchar(3) primary key,
No1 int,
No2 int,
No3 int,
No4 int,
No5 int
)


create table PollingBooth_B(
party_id varchar(3) primary key,
No1 int,
No2 int,
No3 int,
No4 int,
No5 int
)


这两个表用于存储一些投票值.....这两个表位于单独的数据库中,并且,还有另一个表称为maintable,我想将PollingBooth_A,PollingBooth_B值添加到该表中作为摘要


these two tables are using to store some voting values.....these two are in a seperate database,,,and there is another table called maintable and i want to add PollingBooth_A,PollingBooth_B values to that table as a summary

create table maintable(
party_id varchar(3) primary key,
No1 int,
No2 int,
No3 int,
No4 int,
No5 int
)



例如:

PollingBooth_A
1 = 12
PollingBooth_B
1号= 10
然后在maintable
1 = 12 + 10 = 22

我没有任何想法怎么做!有帮助吗?谢谢....



example:

PollingBooth_A
No1 = 12
PollingBooth_B
No1 = 10
then in maintable
No1 = 12+10 = 22

i dnt hv any idea how to do it!! any help?? thank you....

推荐答案

尝试一下(不要忘记填写...直到No5):
Try this (don''t forget to fill in the ... up until No5):
INSERT INTO maintable(party_id, No1, No2, ...) 
  SELECT A.party_id, A.No1 + B.No1, A.No2 + B.No2, ...
    FROM PollingBooth_A AS A,
         PollingBooth_B AS B
    WHERE A.party_id = B.party_id;


祝你好运!


Good luck!


Update maintable
set no1= a.no1+b.no1
from PollingBooth_A as 
Inner Join PollingBooth_B as b on b.party_id = a.Party_id
Inner join maintable as mt on mt.party_id = a.Party_id
where mt.party_ID = @party_Id  --declare this parameter so it knows which row has to be updated


我已经使用了3个表tab1,tab2 ,tab3,每个col1,col2作为int类型的两列.根据您的表进行修改.我已经假设tab1和tab2的col1为主键,而col1的顺序值为1,2,3,4,5
如果不是这种情况,您可能需要删除循环
I have used 3 tables tab1,tab2,tab3 each having col1,col2 as two columns of type int. Modify this according to your tables. i have assumed col1 of both tab1 and tab2 as primary key and sequential values for col1 as 1,2,3,4,5
You may need to remove the loop if taht not the case
declare @i int
set @i=0
declare @max int
 select @max=count(*) from tab1
while(@i<@max)
BEGIN
declare @sum1 int
declare @sum2 int

select @sum1=a.col1+b.col1 from tab1 a JOIN tab2 b ON a.col1=b.col1 where a.col1=@i
select @sum2=a.col1+b.col1 from tab1 a JOIN tab2 b ON a.col1=b.col1 where a.col1=@i

select a.col2+b.col2 from tab1 a JOIN tab2 b ON a.col1=b.col1
insert into tab3(col1,col2) 
values(@sum1,@sum2)
set @i=@i+1

END



Best of LucK ......... !!



Best of LucK.........!!


这篇关于如何将两个单元格值相加的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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