Introduction
We use SELECT with expressions and calculations to get new information by doing math or combining data right when we ask the database.
SELECT column1, column2, (expression) AS alias_name FROM table_name;
SELECT price, quantity, price * quantity AS total_cost FROM sales;
SELECT first_name, last_name, first_name || ' ' || last_name AS full_name FROM employees;
SELECT birth_year, 2024 - birth_year AS age FROM users;
CREATE TABLE products (product_name TEXT, price DECIMAL, quantity INT); INSERT INTO products VALUES ('Pen', 1.5, 10), ('Notebook', 3.0, 5), ('Eraser', 0.5, 20); SELECT product_name, price, quantity, price * quantity AS total_value FROM products;
SELECT price * quantity AS total_cost FROM sales; do?orders with columns price and quantity, what is the output of this query?SELECT price, quantity, price * quantity AS total FROM orders WHERE price = 10;
SELECT price + quantity AS total FROM sales WHERE total > 100;
discounted_price. Which query correctly applies the discount and rounds the result to 2 decimals?Pass the test and this pattern moves unknown