ADDITION Operator (+) - SQL
Overview
The Addition operator (+) in SQL adds two numbers together. It can be used in SQL queries to perform arithmetic addition on numeric columns or values.
Syntax:
SELECT number1 + number2
number1 + number2
adds the values of number1
and number2
together.
Sample Data:
first_name | vacation_days |
---|---|
Frank | 5 |
Jane | 2 |
Ashley | 3 |
Glenn | -3 |
Kelly | 2 |
Richard | -7 |
George | 2 |
Kyle | 1 |
James | -2 |
Gustavo | -10 |
Example: Hard-coded values
In this example, the Addition operator is adding up the numbers 5 and 2.
Example:
SELECT 5 + 2
Example: Query without the WHERE Statement
In this example, we are returning the vacation_days column and a calculated column which adds 10 to each value in the vacation_days column. The final output is the original vacation_days column alongside the incremented values column.
Example:
SELECT vacation_days, vacation_days + 10
FROM company.employees
Example: Query with the WHERE Statement
In this example, we are filtering for only rows in department_id 1. We are returning the vacation_days column and a calculated column which adds 10 to each value in the vacation_days column. The final output is the original vacation_days column alongside the incremented values column.
Example:
SELECT vacation_days, vacation_days + 10
FROM company.employees
WHERE department_id = 1