Intermediate SQL
Jasmin Ludolf
Data Science Content Developer, DataCamp
+
, -
, *
, and /
SELECT (4 + 3);
|7|
SELECT (4 * 3);
|12|
SELECT (4 - 3);
|1|
SELECT (4 / 3);
|1|
SELECT (4 / 3);
|1|
SELECT (4.0 / 3.0);
|1.333...|
Aggregate functions
Arithmetic
SELECT (gross - budget)
FROM films;
|?column?|
|--------|
|null |
|2900000 |
|null |
...
SELECT (gross - budget) AS profit
FROM films;
|profit |
|--------|
|null |
|2900000 |
|null |
...
SELECT MAX(budget), MAX(duration)
FROM films;
|max |max|
|-----------|---|
|12215500000|334|
SELECT MAX(budget) AS max_budget,
MAX(duration) AS max_duration
FROM films;
|max_budget |max_duration|
|-----------|------------|
|12215500000|334 |
FROM
WHERE
SELECT
(aliases are defined here)LIMIT
SELECT
clause cannot be used in the WHERE
clause due to order of executionSELECT budget AS max_budget
FROM films
WHERE max_budget IS NOT NULL;
column "max_budget" does not exist
LINE 5: WHERE max_budget IS NOT NULL;
^
Intermediate SQL