Lesson 12 of 30
Calculated columns and aliases
Today at the studio
Jun, the accountant, is the quiet type, but today he comes to your desk. "I need the monthly numbers, not the yearly ones. And I need the columns to have decent names." Byte approves of decent names.
The idea
A column in SELECT can be a calculation: price * 2, salary / 12.0, or any mix of columns and numbers. The calculation runs on every row.
Give a calculated column a name with AS, for example price * units_sold AS revenue. One thing to remember: dividing two whole numbers gives a whole number in SQLite, so write 12.0 when you want decimals.
Example
SELECT product, price * 2 AS double_price FROM merch
Your turn
0 of 4 questions
Question 1 of 4
Show each person's name and monthly salary (salary divided by 12, decimals kept).