## SQL Expressions --- ## SQL Expressions * SELECT Expressions * WHERE Conditions --- ## SELECT Expression * any expression that can produce a column in a SELECT statement * any scalar literal * any column identifier (in a SELECT statement with a FROM clause) * any combination of the above using operators and functions * any subquery --- ## Scalar Literal * number: -10, 20, 3.14, ... * string: 'dog', 'cat', 'house', ... * date: '2023-11-27' * time: '13:27:49.34321' * datetime: '2023-11-27 13:27:49.34321' --- ## Column Identifiers * just the column name if no ambiguity: height * qualified with table name or alias: Player.height (or p.height) --- ## Operators * Arithmetic * Comparison * Logical --- ## Arithmetic Operators * +, -, *, / * % (remainder) * DIV (integer division) --- ## Comparison Operators * =, !=, <, >, <=, >= * LIKE * REGEXP --- ## Logical Operators * ! (logical not) * && (logical and) * || (logical or) * XOR (logical exclusive or) --- ## Operator examples ```sql f.length * f.width p.height < 180 e.role = 'manager' && e.salary > 50000 ``` --- ## Operator example ```sql SELECT length * width AS area, 2*(length+width) AS perimeter FROM frame; ``` --- ## Functions * too many to list! * see MariaDB Function and Operator Reference --- ## Subqueries * a SELECT statment that is part of another SELECT statement ```sql SELECT title, rental_rate FROM film WHERE rental_rate > (SELECT avg(rental_rate) FROM film); ```