当前位置:网站首页>After class, I looked at the document and went back to the lab. I picked up the forgotten SQL operators again
After class, I looked at the document and went back to the lab. I picked up the forgotten SQL operators again
2022-06-11 17:44:00 【Poplar branch】
SQL Those lovely operators under the door
One 、 Arithmetic operator
The overall use of arithmetic operators is relatively simple and clear . There are not many fancy ways to play .
Introduce them systematically ~
One 、 Functions and types
| Arithmetic operators are mainly used for Mathematical operations , It can connect two values or expressions before and after the operator , Add... To a value or expression (+)、 reduce (-)、 ride (*)、 except (/) And modulus (%) operation |
Two 、 Something to watch out for
| It is similar to the use of arithmetic operators in conventional understanding , The precautions are similar , Such as division , The denominator cannot be 0( Otherwise, the result is NULL). The only thing to note is that these operators and NULL When you're doing an operation , All back to NULL |
3、 ... and 、 Summary of arithmetic operators 
All right. ~, There are few cute arithmetic operators now 
Two 、 Comparison operator ( The point of this article )
Comparison operator application scenario
| The comparison operator is used to compare the operands on the left and right of the expression , If the comparison result is true, it returns 1, If the comparison result is false, it returns 0, Other cases return to NULL. |
| Comparison operators are often used as SELECT Query statement To use , Return qualified result records . |
Common comparison operators
| There are many operators for comparison , I hastily divided them into two categories |
One 、 Symbol type 
| It looks like the comparison operator in our normal concept . Let me demonstrate them systematically , By the way, mark the places needing careful attention . |

1、 Equals operator
| seeing the name of a thing one thinks of its function , Directly compare whether the values on both sides of the equal sign are equal . Routinely , Numerical and numerical comparison , String and string comparison really do this . It should be noted that when a numeric value is compared with a string : |

| The second thing you need to know is that the comparison between a string and a string is be based on ANSI code , You can learn about the connection and difference of basic coding through this article |
Line up to pick up the express. At this meeting, I sorted out all kinds of code sets
| The last thing to note is this NULL Worth it |

2、 Security operator
| For security operators , It is roughly the same as the equals operator , The biggest difference is still right NULL Value processing . |

| Its function , The security equals operator can be used to query the table for NULL What's the data of . Others are greater than 、 Less than 、 Less than or equal to these operators are consistent with our conventional understanding , The comparison is based on ANSI code |
Two 、 Alphabetic 
| A lot of them here are the most confusing , It can be roughly combined with their English meaning to remember and understand |

( One )、IS NULL \ IS NOT NULL \ ISNULL
| Their effects , Just like their straightforward Chinese translation . Directly used to query a table The data value is NULL What's the information about . |

It is easy for people to have doubts IS NULL and ISNULL.ISNULL Strictly speaking, it is not an operator , It's a function , This is only because it has similar functions , By the way, mention it |

( Two )、 get minimum value LEAST\ Maximum GREATEST
This is easy to understand , It's also good to translate directly into Chinese . l e a s t least least Minimum means minimum , g r e a t e s t greatest greatest It means the biggest . The principle of comparison is still based on ANSI code

( 3、 ... and )、BETWEEN Conditions 1 AND Conditions 2
| BETWEEN ... AND It's easier to play , Be careful not to make mistakes in logic , For example, when querying, it is written as query greater than or equal to 8000, Less than or equal to 6000. |

( Four )、IN \ NOT IN
| Query data that is in or not in a collection , The main function area is to query discrete data |

( 5、 ... and )、LIKE: Fuzzy query
| The two wildcards you need to master : % and _ % It means : about %a% for , Representative means a There may be 0 One or more characters , as well as a Behind the , There may be zero or more characters . Draw inferences from one instance , If it is %a, Representative means a There may be 0 One or more characters _ It means : An underline _ Represents an indeterminate character |
This is a LIKE and % How to play :
| Let's demonstrate LIKE And the underline _ How to play : |

6、 ... and 、REGEXP \ RLIKE
It is the contents of regular expressions , I don't want to touch it for the time being , I want to write later python The crawler's article , Explain them in more detail 
3、 ... and 、 Logical operators ( As an understanding )
| Role of logical operators : Logical operators are mainly used to judge whether an expression is true or false , stay MySQL in , The return result of the logical operator is 1、0 perhaps NULL |
A summary of logical operators :
| My understanding of logical operators I haven't seen them yet SQL What kind of flowers do you play with ( Maybe it's because I'm ignorant , I don't know if there's any boss to give me some advice , I will make it up in time ( The dog's head lives )) |

| The design of logical operators that I now encounter is mainly limited to the judgment of the upper bell . First introduce them systematically , I have a concept in mind . Students engaged in algorithms may be familiar with logical operators , They are combined with the following bit operations , You can really play with some flowers ~ |

| 1、 Logical nonoperator : Logic is not (NOT or !) Indicates when the given value is 0 When to return to 1; When the given value is non 0 Value returns 0; When the given value is NULL when , return NULL. |
| 2、 Logic and operators Logic and (AND or &&) The logical and operator is when all the given values are non 0 value , And not for NULL when , return 1; When given A value Or multiple values are 0 When you return to 0; Otherwise return to NULL. |
| 3、 Logical or operator Logic or (OR or ||) Logical or operator is when the given value is not NULL, And any value is non 0 When the value of , Then return to 1, Otherwise return to 0; When a value is NULL, And the other value is non 0 When the value of , return 1, Otherwise return to NULL; When both values are NULL when , return NULL. |
| 4、 Logical XOR operator Logical XOR (XOR) The logical XOR operator is when any one of the given values is NULL when , Then return to NULL; If two are not NULL The values are all 0 Or it doesn't mean 0 when , Then return to 0; If a value is 0, The other value is not 0 when , Then return to 1. |
You should be able to get here we are ,SQL They are similar to what we learned in the basic computer course , Just still need to consider NULL The problem of
Four 、 An operator ( As an understanding )
| The effect of bit operation : The bitwise operator is in Calculate on binary numbers Operator . Bit operators first convert operands to binary numbers , And then we do bit operations , Finally, the calculation result is changed from binary to decimal . |
Bit operation summary :
| I feel like SQL in , Bit operation is also an understanding , I'm not very good at get To its effect . Mr. Qian Xuesen said , Having a sword without a sword is two different things , First, roughly grasp it . |

| Introduce them systematically , Old rules , Don't try to remember , Sweep it over , Just have an impression , If you really want to use , You can understand the principle by turning over the contents here |
1、&( Bit and )
Up and down , According to the operation rules of and :0&0=0 ;0&1=0;1&1=1
for example :
170 & 75 The result is :0000 0000 0000 1010
Then convert binary to decimal :10
2、~( Bit non )
Algorithm :0 change 1,1 change 0
for example :
~170 Binary system :1111 1111 0101 0101 Decimal system :-171~75 Binary system :1111 1111 1011 0100 Decimal system :-76
3、|( Bit or )
Up and down , According to the operation rules of and :0&0=0 ;0&1=1;1&1=1
for example :
170 & 75 The result is :0000 0000 1110 1011
Then convert binary to decimal :235
4、^( Bit exclusive or )
Up and down , According to the operation rules of and :0&0=0 ;0&1=1;1&1=0
for example :
170 & 75 The result is :0000 0000 1110 0001
Then convert binary to decimal :225
5、 Bitwise shift right operator
Right shift to position (>>) Operator shifts all bits of the binary number of a given value to the right by the specified number of bits . Shift the specified number of bits to the right , The lower value on the right is removed and discarded , The left high position is empty with 0 A filling .
6、 Bitwise shift left operator
* Move left according to position (<<) Operator shifts all bits of the binary number of a given value to the left by the specified number of bits . Move the specified number of bits left , The higher left value is removed and discarded , On the right side, the low position is left by 0 A filling .
Operator precedence
| This table of operator priorities , There is no need to memorize it deliberately , In my opinion , In addition to the cute test will encounter priority questions , In actual use, you can use parentheses to solve . Old rules , Go over it , It's good to have an impression . |

summary
| 1、 First of all, for the =、<、> These operators are also used in our concept , Pay special attention to encounter SQL peculiar NULL When it's worth it , Most of the returned results are NULL, Therefore, the security operator was born <=> To deal with this matter 2、 Focus on the comparison operators that are English words , It is good to understand it in combination with the Chinese meaning 3、 Logical operators and bitwise operations are good to understand ~, As your own internal skill . As well as the priority to deal with the exam . |
We're in the lab ~, Look at the little prince for a while 
Small exercise
| If you want to deepen your understanding or memory, you can get a few exercises to practice your hands from this link , Are relatively simple , I believe you can get them in seven or eight minutes |

notes : I don't know gitee What's going on , Sometimes the first time I open the uploaded content, it will show what is illegal , So let's make a special point , It's all formal content ,F5 Just refresh it ~

Click here to get the exercises
边栏推荐
- Authing biweekly news: online application market (5.10-5.22)
- 6-6 批量求和(*)
- Chorus翻译
- MFSR:一种新的推荐系统多级模糊相似度量
- 【深度学习基础】神经网络的学习(3)
- Speed adjustment of tidb DDL
- 6-2 多个整数的逆序输出-递归
- Bentley uses authing to quickly integrate application system and identity
- 6-3 reading articles (*)
- Tidb CDC create task error unknown or incorrect time zone
猜你喜欢

Port planning and APJ
![[foundation of deep learning] learning of neural network (3)](/img/a5/1b80ba85faf8fa636b784c76d4df2f.png)
[foundation of deep learning] learning of neural network (3)

What problems are exposed when all Sohu employees are cheated?

Windows technology - how to view the instruction set, model, attribute and other details supported by the CPU, and how to use the CPU-Z tool to view the processor, memory, graphics card, motherboard,

04_特征工程—特征选择

Threejs uses indexeddb cache to load GLB model

【先收藏,早晚用得到】100个Flink高频面试题系列(一)

智能化整体图例,布线、安防、广播会议、电视、楼宇、消防、电气图的图例【转自微信公众号弱电课堂】

Service learning notes 01 start method and life cycle

【Mysql】redo log,undo log 和binlog详解(四)
随机推荐
信息安全数学基础 Chapter 2——同余
6-3 reading articles (*)
6-8 创建、遍历链表
Hash表、 继承
6-7 文件读写操作
tidb-cdc创建任务报错 Unknown or incorrect time zone
Semaphore PV operation of process interaction and its code implementation
TestPattern error
Service学习笔记02-实战 startService 与bindService
6-8 有结构文件的读写1
送给大模型的「高考」卷:442人联名论文给大模型提出204个任务,谷歌领衔
7-1 均是素数
Tidb CDC create task error unknown or incorrect time zone
6-2 多个整数的逆序输出-递归
你还不懂线程池的设计及原理吗?掰开揉碎了教你设计线程池
Tidb GC related problems
合并K个升序链表---2022/02/26
R language to find missing value location of data set
Biden ordered to enforce the zero trust structure
Bentley uses authing to quickly integrate application system and identity