Arithmetic operators perform mathematical operations on numeric values in SQL expressions.
value_expression operator value_expression
Operator | Description |
---|---|
+ | Addition |
- | Subtraction |
* | Multiplication |
/ | Division |
% | Modulo (remainder) |
SELECT 5 + 3;
-- Result: 8
SELECT price + tax AS total_cost FROM orders;
SELECT 10 - 4;
-- Result: 6
SELECT current_balance - withdrawal AS new_balance FROM accounts;
SELECT 7 * 8;
-- Result: 56
SELECT quantity * unit_price AS line_total FROM items;
SELECT 20 / 4;
-- Result: 5
SELECT total_amount / number_of_people AS amount_per_person FROM expenses;
SELECT 17 % 5;
-- Result: 2
SELECT order_id % 10 AS routing_key FROM orders;