← Back
LESSON 9
SQL (Core) - Queries with expressions
Prereq: None | Progress: 0%
Course Syllabus
Lesson 0 📖 What is SQL? Lesson 1 📖 SELECT queries 101 Lesson 2 📖 Queries with constraints (Pt. 1) Lesson 3 📖 Queries with constraints (Pt. 2) Lesson 4 📖 Filtering & sorting results Review 1 📖 Simple SELECT Queries Lesson 6 📖 Multi-table queries with JOINs Lesson 7 📖 OUTER JOINs Lesson 8 📖 A short note on NULLs Lesson 9 📖 Queries with expressions Lesson 10 📖 Queries with aggregates (Pt. 1) Lesson 11 📖 Queries with aggregates (Pt. 2) Lesson 12 📖 Order of execution of a Query Lesson 13 📖 Inserting rows Lesson 14 📖 Updating rows Lesson 15 📖 Deleting rows Lesson 16 📖 Creating tables Lesson 17 📖 Altering tables Lesson 18 📖 Dropping tables Lesson 19 📖 Subqueries & Nested Queries Lesson 20 📖 Set Operations Summary 🎓 Course Completion
Queries with expressions
In addition to fetching raw column values, SQL allows you to perform arithmetic calculations, string transformations, and logical functions directly inside your SELECT expressions.
1. Calculated Columns & Arithmetic Syntax
SELECT title, (domestic_sales + international_sales) / 1000000 AS total_sales_millions FROM movies JOIN boxoffice ON movies.id = boxoffice.movie_id;
Mathematical operators (+, -, *, /, %) can transform numeric columns on the fly.
2. Column Aliases with AS
Using the AS alias_name keyword renames the computed column output header so that result sets remain readable and clear.
🗄️ Schema Explorer SELECTABLE
› movies
|
🎯 Exercises Checklist:
☐ 1. List all movies and their combined sales in millions of dollars
☐ 2. List all movies and their ratings in percent
☐ 3. List all movies that were released on even number years
⚡ Practice Console
💡 Hint:
Loading hint...
🔑 Solution SQL:
SELECT * FROM movies; Data Output
No results. Run query to fetch data.