当前位置:网站首页>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
边栏推荐
猜你喜欢

Ffmpeg hard codec inter QSV

ADB command learning notes

Port planning and APJ

你还不懂线程池的设计及原理吗?掰开揉碎了教你设计线程池

Semaphore PV operation of process interaction and its code implementation

Leetcode force deduction question

合并K个升序链表---2022/02/26

Why is the UDP stream set to 1316 bytes

光纤熔接知识汇总【转载自微信公众号弱电智能化工程2018】

Activity | authing's first channel cooperation activity came to a successful conclusion
随机推荐
Typescipt Basics
Set object mapping + scene 6-face mapping + create space in threejs
Semaphore PV operation of process interaction and its code implementation
Kubernetes deploys elk and collects container logs using filebeat
Authing biweekly news: authing forum launched (4.25-5.8)
Vscode configures eslint to automatically format an error "auto fix is enabled by default. use the single string form“
智能化整体图例,布线、安防、广播会议、电视、楼宇、消防、电气图的图例【转自微信公众号弱电课堂】
6-1 需要多少单词可以组成一句话?
6-6 批量求和(*)
CentOS7服务器配置(四)---安装redis
which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_ mod
6-3 reading articles (*)
信息安全数学基础 Chapter 3——有限域(二)
Why is the UDP stream set to 1316 bytes
【题解】Codeforces Round #798 (Div. 2)
Test and analysis of tidb write hotspot
有效的括号---2022/02/23
为什么udp流设置1316字节
Use exe4j to convert The jar file is packaged as Exe file
Ffmpeg hard codec inter QSV