mysql query conditions, logic queries, fuzzy queries, wildcard escape character

Conditions inquiry

select list of queries from table where the filter criteria;

classification:

Conditional Expression Filter =,! =
Logical expression screening and or not
fuzzy query like, between and, in, is null

Queries salary is greater than 12,000 employee information

SELECT * FROM employees WHERE salary >12000;

Queries department number ranging from 90 employees name and department number, to query number

SELECT last_name,department_id FROM employees WHERE department_id <>90;

Filter by logical expression

Queries employees' wages were between 10,000 to 20,000, wages and bonuses

SELECT last_name ,salary,commission_pct FROM employees WHERE salary<20000
AND salary>10000;

Queries department number is not between 90-110, or paid more than 15,000 employees

SELECT
    *
FROM employees
WHERE department_id <90 
OR  department_id >110
OR      salary>15000;
#或者
SELECT *
FROM employees
WHERE  NOT(department_id>=90 AND department_id<=110) OR salary>15000;

Fuzzy query
like, query employee information employee name contains characters of a

SELECT 
    *
FROM 
    employees
WHERE
    last_name LIKE '%a%';   //百分号%是通配字符,代表其他任意多个字符,_代表任意一个字符

Case: employee name query third character is e, as a fifth character names and salaries of employees

SELECT 
    last_name,
    salary
FROM employees
WHERE 
    last_name LIKE '__e_a%';  //2个下划线+e+一个下划线+a

Case: employee name query the second character is _ the name of the employee, the normal escape character \

SELECT 
    last_name
FROM 
    employees
WHERE
    last_name LIKE '_\_%';

Custom escape character

SELECT 
    last_name
FROM 
    employees
WHERE
    last_name LIKE'_@_%' ESCAPE '@';

Guess you like

Origin blog.51cto.com/14437184/2434598