sql查询从两个表中添加两列. [英] sql query to add two columns from two table..

查看:1388
本文介绍了sql查询从两个表中添加两列.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我们分别有两列,分别来自table1和table2的column1和column2.添加列1和列2并在列1中设置值的SQL查询是什么?

请帮助我.

Suppose we have two columns, column1 and column2 from table1 and table2 respectfully. What is the SQL Query to add column1 and column2 and set the value in column1?

Help me please.

推荐答案

update table1 set column1 = column1 + column2 
from table2 where
table2.id = table1.id


查看联合查询

http://www.w3schools.com/sql/sql_union.asp [
Look at Union query

http://www.w3schools.com/sql/sql_union.asp[^]


假设我们有两列,分别来自table1和table2的column1和column2.添加列1和列2并在列1中设置值的SQL查询是什么?

您将需要编写一个 SP 并使用 Cursors 来遍历表的所有行.

其他选择可以是使用表值函数进行相同的操作.
Suppose we have two columns, column1 and column2 from table1 and table2 respectfully. What is the SQL Query to add column1 and column2 and set the value in column1?

You would need to write a SP and use Cursors to loop through all the rows of the table to do it.

Other option can be to use Table Valued Function to do the same.


这篇关于sql查询从两个表中添加两列.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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