Sql - Expressions and calculations
Code Life
By Pierre Marsaa
Calculating in SELECT
A SELECT doesn't only read columns: it can also compute values. You can use the arithmetic operators +, -, * and / directly on columns.
Here is the Codémon table we'll use in this chapter:
Loading data...
Let's double the power of every Codémon:
↗️
Loading editor...
↶
↷
Each row gets a new value computed from its own power. The table itself is not modified: an expression only exists in the result of the query.
SELECT as a calculator
You can even run a SELECT without any table: SELECT 7 * 6; simply returns 42. Handy for quick checks!
Verify