当前位置:网站首页>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;边栏推荐
- 疫情之下,台积电一季度增长超预期,7nm占比35%!二季度或创新高
- 【ELM分类】基于核极限学习机和极限学习机实现UCI数据集分类附matlab代码
- reduce错误示范
- 【软考软件评测师】2014综合知识历年真题
- 【信号处理】基于高阶统计量特征的通信系统中微弱信号检测附matlab代码
- XML 外部实体 (XXE) 漏洞及其修复方法
- ELK日志分析系统安装和部署
- My annual salary is 1million, and I don't have clothes more than 100 yuan all over my body: saving money is the top self-discipline
- ZCMU--1720: 死亡如风,我要装逼
- 进程同步的方式有哪些?
猜你喜欢

Nature综述:微生物群落形成过程中的优先效应

Blender plug-in of 2022
编辑复制粘贴判定问题(bug?),所见即所得显示符号问题反馈。
![[number recognition] handwritten number recognition based on knowledge base with matlab code](/img/06/6adab955a339f453249543baab1dc6.png)
[number recognition] handwritten number recognition based on knowledge base with matlab code

The technology of applet container is very promising, which can greatly improve the efficiency of mobile R & D

CaEGCN: Cross-Attention Fusion based Enhanced Graph Convolutional Network for Clustering 2021

2022夏暑假每日一题(五)

真的很难理解?RecyclerView 缓存机制到底是几级缓存?

With double-digit growth in revenue and profit, China Resources Yibao has quietly created these new products worth more than 100 million

小程序容器技术超有料,可以让移动研发效率大幅提升
随机推荐
With double-digit growth in revenue and profit, China Resources Yibao has quietly created these new products worth more than 100 million
【 图像去雾】基于暗通道和非均值滤波实现图像去雾附matlab代码
How to use xshell Free Edition
NDK 系列(6):说一下注册 JNI 函数的方式和时机
初步了解Panda3D音频和高级交互组件
What are the methods of process synchronization?
数据中台的那些“经验与陷阱”
My annual salary is 1million, and I don't have clothes more than 100 yuan all over my body: saving money is the top self-discipline
[number recognition] recognize 0-9 numbers based on Hopfield neural network with matlab code
【软考软件评测师】2014综合知识历年真题
7.6万人停工!东芝宣布关闭日本所有工厂
一加将在2020年释放ODM订单,发力中低端市场
[signal denoising] signal denoising based on Kalman filter with matlab code
Implicit indicators for evaluating the advantages and disadvantages of automated testing
Huawei Hongmeng 3 was officially released, and this security feature has solved a major pain point
许锦波:AI蛋白质预测与设计
Sudden, wechat important notice
图基本知识代码
【JS 逆向百例】某公共资源交易网,公告 URL 参数逆向分析
如何快捷地查看H.265视频播放器EasyPlayer的API属性及其使用方法?