在 SQL 中,加法运算符 (+) 可用于对数值进行加法运算。语法如下:
SELECT column1 + column2 FROM table_name;
其中:
* column1
和 column2
是包含数值的列。
* table_name
是要查询的表。
示例
例如,以下查询对表 sales
中的 sales_quantity
和 sales_price
列进行加法运算:
SELECT sales_quantity + sales_price FROM sales;
此查询将返回一个新列,其中包含 sales_quantity
和 sales_price
列的和。
其他用法
加法运算符还可以用于其他场景,例如:
* 将常量添加到数值:SELECT 5 + sales_quantity FROM sales;
* 将函数结果添加到数值:SELECT SUM(sales_quantity) + 100 FROM sales;
注意事项
* 确保加法运算符两侧的表达式的数据类型都为数值。否则,查询可能会出错。
* 加法运算符还可以用于字符串连接。在这种情况下,它会将两边的字符串连接在一起,而不是进行数学加法。