sql两列相加
在SQL中,可以使用+运算符将两个列的数据相加。例如,如果有一个名为column1和column2的表格,可以使用以下语句将它们相加:
SELECT column1 + column2 AS sum FROM table_name;
AS sum是为相加后的结果指定一个别名,可以根据需要进行调整。
此外,如果需要将两个表格中的相同列相加,可以使用union或union all关键字。具体语法为:
select <列名>,<列名>,… from <表名1> union select <列名>,<列名>,... from <表名2> 。
注意,union和union all的主要区别在于,union all会保留重复的行。
