当前位置:网站首页>MySQL data query (where)
MySQL data query (where)
2022-07-27 23:39:00 【Yu'an.112】
WHERE The clause must be immediately followed by FROM After Clause , stay WHERE clause , Use a condition from FROM Select a row from the intermediate result of the clause . Grammar format :WHERE < Decision operation >
Decision operation : The result is true、false or unknown
WHERE Clauses will match FROM The intermediate result of the clause is judged row by row , When conditions are ture when , One line is included in WHERE Intermediate result set of clause .
stay SQL in , Returns the logical value (true or false) Operators or keywords of can be called predicates , Decision operation includes comparison operation 、 Pattern matching 、 Range comparison 、 Null value comparison and subquery .
1、 Comparison operations
The comparison operator is used to compare two expression values ,MySQL The supported comparison operators are :=( be equal to ),<( Less than ),<=( Less than or equal to ),>( Greater than ),>=( Greater than or equal to ),<=>( Equal or equal to nothing ),<>( It's not equal to ),!=( It's not equal to ).
Expression is division TEXT and BLOB Expressions outside of type .
When both expression values are not null (NULL) when , except “<=>” Operator , Other comparison operations return logical values true( really ) or false( false ). When one of the two expression values is null or both are null , Will return unknown.
example : Inquire about Bookstore database book The title of the book in the table is “ Web programming ” The record of
SELECT *
FROM book
WHERE Title =' Web programming ';example : Inquire about Book The unit price in the table is greater than 30 Books of
SELECT *
FROM Book
WHERE The unit price >30;MySQL There is one special The equal operator of “<=>”, When two expressions are equal to each other or both are equal to null , The value of the operation is true, When there is a null value or both non null values but not equal, the result of this condition is false, But not unknown The situation of .
2、 Logical operations
Logical operation can pass the results of multiple decision operations through logical operators (AND、OR、XOR and NOT) Form more complex query conditions .
Logical operators are used to test a condition , The result of operation is true(1) or false(0).MySQL The logical operators provided are :
not or !: Logic is not
or or ||: Logic or
and or &&: Logic and
xor: Logical XOR
The result of logical operation is 1 or 0, respectively true and false.
3、 Pattern matching
LIKE The operator is used to indicate whether a string matches the specified string , Its operands can be char、varchar、text、datetime And so on , Returns the logical value true or false.
Grammar format : expression [not] LIKE expression
Use LIKE When pattern matching , Special symbols are often used _ and % Fuzzy query ,% representative 0 Characters or more ,_ Single character .
because MySQL Case insensitive by default , To be case sensitive, you need to change the proofing rules of the character set .
example : Inquire about Members Last name in the table “ Zhang ” Member's ID number 、 full name 、 Registration time
SELECT ID number , Membership name , Registration time
FROM Members
WHERE Membership name LIKE' Zhang %';example : Inquire about book The book number in the table is the penultimate 2 Position as D Book number and title
SELECT Book number , Title
FROM book
WHERE Book number LIKE'%D_';To find one or all of the special symbols (_ and %), An escape character must be used . When looking for underscores _ when , have access to ESCAPE'#' To define # For escape characters , such , In the statement # hinder _ It loses its original special significance , Underline that is considered normal _.
example : Inquire about book Books with underlined titles in the table .
SELECT Book number , Title
FROM book
WHERE Title LIKE'%#_%'ESCAPE'#';4、 Range comparison
There are two keywords used for range comparison , Namely BETWEEM and IN
When the condition to be queried is a range of values , have access to BETWEEN keyword .BETWEEN Keywords indicate the query scope , The format is : expression [NOT] BETWEEN expression 1 AND expression 2
example : Inquire about Book In the table 2003 The situation of books published in
SELECT *
FROM Book
WHERE Publication date BETWEEN'2003-1-1' AND '2003-12-31';
# or
SELECT *
FROM Book
WHERE Publication date >='2003-1-1' AND Publication date <='2003-12-31';example : To find out Book It's not in the table 2003 The situation of all books published in , Use NOT
SELECT *
FROM Book
WHERE Publication date NOT BETWEEN '2003-1-1' AND '2003-12-31';
# or
SELECT *
FROM Book
WHERE Publication date <='2003-1-1' OR Publication date >='2003-12-31';Use IN Keywords can specify a value table , All possible values are listed in the value table , When it matches any one in the value table , Return true, Otherwise return to false.
Grammar format : expression [NOT] IN( Subquery | expression 1[,... expression n])
IN The most commonly used keywords are expression sub queries , It can also be used for OR operation .
example : Inquire about Book In the table “ Higher Education Press ”,“ Peking University press ” and “ People's University Press ” Published books
SELECT * FROM Book
WHERE Press. IN(' Higher Education Press ',' Peking University press ',' People's University Press ');
# or
SELECT * FROM Book
WHERE Press. =' Higher Education Press '
OR Press. =' Peking University press '
OR Press. =' People's University Press ';5、 Empty value comparison
When it is necessary to determine whether the value of an expression is null , Use IS NULL keyword .
Grammar format : expression IS [NOT] NULL
If the value of the expression is null , return true, Otherwise return to false, When using not when , The result is just the opposite .
example : Inquire about Sell Order records in the table that have not been shipped
SELECT *
FROM Sell
WHERE Whether to ship the goods or not IS NULL;边栏推荐
- Process and planned task management
- Current situation and future of Nb IOT industry: cross the threshold of 100million shipments and rush to 5g connection!
- Zabbix4.0 uses SNMP agent to monitor vcenter6.5
- 编辑复制粘贴判定问题(bug?),所见即所得显示符号问题反馈。
- Learn more about xxE injection
- TSMC 3nm detail exposure: transistor density as high as 250million /mm ², Greatly improved performance and energy efficiency
- Disable caching with meta HTML tags in all browsers
- 【数字识别】基于知识库实现手写体数字识别附matlab代码
- 进制转换方法
- JUC工具包学习
猜你喜欢

File&递归14.1
Software test function test full set of common interview questions [function test] interview summary 4-2
![[soft test software evaluator] 2014 comprehensive knowledge over the years](/img/85/46c8fc696ae5249a9aca22b50493f0.jpg)
[soft test software evaluator] 2014 comprehensive knowledge over the years
![[GNN report] Tang Jian, Montreal, Canada: Geometric deep learning for drug discovery](/img/ef/aa490aeff5a0690257cd6eca7d5e28.png)
[GNN report] Tang Jian, Montreal, Canada: Geometric deep learning for drug discovery

怎么使用C# Winform实现复制文件显示进度

用3dmax做折扇的思路方法与步骤

Sudden, wechat important notice

突发,微信重要通知

【数字识别】基于知识库实现手写体数字识别附matlab代码

【GNN报告】加拿大蒙特利尔唐建:Geometric Deep Learning For Drug Discovery
随机推荐
请求合并哪家强——接口请求合并的3种技巧,性能直接爆表
新技术引领大中型企业营销新变革,用友BIP CRM重磅发布!
C#委托用法--控制台项目,通过委托实现事件
数据管理的重点
Pentium快速系统调用学习
Join hands with Changjiang storage, jiangbolong launches the world's smallest expansion card
What are the methods of process synchronization?
360 was selected into the panorama of China's security industry, and isc2022 talked about the direction of security services in 63 fields
编辑复制粘贴判定问题(bug?),所见即所得显示符号问题反馈。
After returning to mixlab for three days, "creative team" cured my spiritual internal friction
Normality of confidence interval
使用灰度滤镜
Socket interaction process of three handshakes
In 2019, the world's top ten semiconductor manufacturers: Intel returned to the first place, and apple rose sharply against the trend
Tita 的OKR系统与其他同类型产品,或者是共享文档等相比,有什么优势?
Common Taylor expansion
常用泰勒展开
Socket interaction process of four waves
File&递归14.1
Xu Jinbo: AI protein prediction and design