Computed columns in SQL
A SELECT list holds expressions, not just column names.
SELECT
sku,
price,
ROUND(price * 1.2, 2) AS price_with_tax,
name || ' (' || sku || ')' AS label,
'catalog' AS source
FROM products;
How it works
- Arithmetic works on columns;
ROUNDtakes the number of decimals. ||concatenates strings — SQL's+is only ever addition.- A literal column is legal and useful for tagging rows.
Keywords and builtins used here
ASFROMSELECTsource
The run, in numbers
- Lines
- 7
- Characters to type
- 131
- Tokens
- 37
- Three-star pace
- 70 tpm
At the three-star pace of 70 tokens a minute, this run takes about 32 seconds.
Step 3 of 5 in Selecting rows, step 3 of 23 in Language basics.