Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Mysql conditional query, logical query, fuzzy query, wildcard, escape character

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

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'@'

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report