Mysql conditional query, logical query, fuzzy query, wildcard, escape character
Wildcard characters are unequal for null
Conditional query
Select query list from table name where filter
Classification:
Filter = by conditional expression,! =
Filter and or not by logical expression
Fuzzy query like, between and, in, is null
Query the information of employees whose salary is greater than 12000.
SELECT * FROM employees WHERE salary > 12000
Query the employee name and department number for which the department number is not equal to 90, and the number to be queried
SELECT last_name,department_id FROM employees WHERE department_id 90
Filter by logical expression
Inquire about the name, salary and bonus of employees with salaries between 10000 and 20000
SELECT last_name, salary,commission_pct FROM employees WHERE salary10000
Inquire about employees whose department numbers are not between 90 and 110, or whose wages are higher than 15000.
SELECT * FROM employeesWHERE department_id 110OR salary > 15000 SELECT # or SELECT * FROM employeesWHERE NOT (department_id > = 90 AND department_id15000
# find the employee's name and salary are not between 8000 and 17000, and are arranged in the order of wage increase
SELECT last_name, salaryFROM employeesWHERE salary NOT BETWEEN 8000 AND 17000ORDER BY salary ASC
Fuzzy query
Like, query the employee information that contains the character an in the employee name
SELECT * FROM employeesWHERE last_name LIKE'% a% characters; / /% sign% is a wildcard character, which represents any number of other characters, and _ represents any character.
Case study: query the employee name and salary with the third character e and the fifth character an in the employee name
SELECT last_name, salaryFROM employeesWHERE last_name LIKE'_ e% underscore; / / 2 underscores + e + one underscore + a
Case: query the employee name with the second character _ in the employee name, and the normal escape character\
SELECT last_nameFROM employeesWHERE last_name LIKE'_\%'
Custom escape character
SELECT last_nameFROM employeesWHERE last_name LIKE'_@_%' ESCAPE'@'