当前位置:网站首页>MySQL advanced (Advanced) SQL statement (II)
MySQL advanced (Advanced) SQL statement (II)
2022-07-02 03:15:00 【Richard_ Chiang】
MySQL senior ( Advanced )SQL sentence ( Two )
Four 、MySQL Union set 、 Intersection value 、 No intersection value 、case

1、UNION----- combine
- Put two SQL The results of the statement are combined , Two SQL The fields generated by the statement need to be of the same data type

UNION ALL

2、 Intersection value
- Take two. SQL The intersection of statement results

- There are no duplicate rows in the two tables , The row of the other table is repeated and does not apply , Use when two tables do have intersecting rows

- Take two. SQL The intersection of statement results , And there's no repetition

3、 No intersection value
- Show the first SQL Result of statement , And with the second SQL Statement has no result of intersection , And there's no repetition

4、CASE
- CASE yes SQL Used for IF-THEN-ELSE And so on

5、 ... and 、 Sort
Case study :

1、 Rank
- Form self linking (Self Join), Then list the results in order , Before you figure out each line ( Including the line itself ) How many lines are there

2、 Count the median

3、 To add up
- Form self linking (Self Join), Then list the results in order , Before you figure out each line ( Including the line itself ) The sum of

4、 Total percentage

5、 Calculate the cumulative total percentage
- With cumulative total SUM(a2.Sales) Divide by the total to find the cumulative total percentage of each row

- Take a few digits after the decimal point

6、 ... and 、 Null value (NULL) and No value (‘’) The difference between
- The length of no value is 0, Not taking up space ; and NULL The length of the value is NULL, It takes up space .
- IS NULL perhaps IS NOT NULL, It is used to judge whether the field is NULL Or not NULL, Can't find out if it's worthless .
- The judgment without value uses =’‘ perhaps <>’' To deal with it .<> The representative is not equal to .
- Through count() When specifying the number of rows in the field statistics , If you encounter NULL The value is automatically ignored , If there is no value, it will be added to the record for calculation .

- test



7、 ... and 、MySQL Regular expressions of
| Matching mode | describe | example |
|---|---|---|
| ^ | Match the start character of the text | ‘^bd’ Match with bd Starting string |
| $ | Match the end character of the text | ‘qn$’ Match with qn a null-terminated string |
| . | Match any single character | ‘s.t’ Match any s and t A string with one character between |
| * | Match zero or more characters before it | ‘fo*t’ matching t There is any one in front o |
| + | Match preceding characters 1 Times or times | ‘hom+’ Match with ho start , At least one back m String |
| character string | Match contains the specified string | ‘clo’ The match contains clo String |
| p1|p2 | matching p1 or p2 | ‘bg|fg’ matching bg perhaps fg |
| […] | Match any character in the character set | ‘[abc]’ matching a perhaps b perhaps c |
| [^…] | Match any characters that are not in brackets | ‘[ ^ ab]’ Match does not contain a perhaps b String |
| {n} | Match the previous string n Time | ‘g{2}’ The match contains 2 individual g String |
| {n,m} | Match the previous string at least n Time , at most m Time | ‘f{1,3}’ matching f least 1 Time , most 3 Time |
Grammar format :

8、 ... and 、 stored procedure
1、 The concept of stored procedure
- A stored procedure is a set of functions to accomplish SQL Statement set .
- In the process of using stored procedures, common or complex work is used in advance SQL The statement is written and stored with a specified name , This process is compiled and optimized and stored in the database server . When you need to use this stored procedure , Just call it . Stored procedures perform better than traditional SQL Faster 、 More efficient execution .
2、 Advantages of stored procedures
- After one execution , The generated binary code will reside in the buffer , Improve execution efficiency
- SQL Statement plus a collection of control statements , High flexibility
- Store on the server side , When called by the client , Reduce network load
- Can be called repeatedly , Can be modified at any time , Does not affect client calls
- Can complete all database operations , You can also control the information access rights of the database
3、 Create stored procedure

4、 Calling stored procedure

5、 View stored procedures

6、 Parameters of stored procedure
- IN Input parameters : Indicates that the caller passes a value... To the procedure ( The incoming value can be literal or variable )
- OUT Output parameters : Indicates that the procedure passes out a value to the caller ( Multiple values can be returned )( Outgoing values can only be variables )
- INOUT Input/output parameter : It means that the caller passes in a value to the procedure , It also indicates that the procedure passes out a value to the caller ( Values can only be variables )
for example :

7、 Delete stored procedure
The method to modify the contents of stored procedures is to delete the original stored procedures , Then create a new stored procedure with the same name .

8、 Control statement of stored procedure

(1) Conditional statements if-then-else-end if


(2) Loop statement while/end while


边栏推荐
- 命名块 verilog
- Grpc快速实践
- Actual battle of financial risk control - under Feature Engineering
- Cache processing scheme in high concurrency scenario
- Verilog parallel block implementation
- Qualcomm platform WiFi -- Native crash caused by WiFi
- Halcon image rectification
- 【JVM】创建对象的流程详解
- MongoDB非關系型數據庫
- Global and Chinese market of bone adhesives 2022-2028: Research Report on technology, participants, trends, market size and share
猜你喜欢
随机推荐
Work hard all day long and be alert at sunset
Cache processing scheme in high concurrency scenario
venn图取交集
C shallow copy and deep copy
C # joint halcon out of halcon Environment and various Error Reporting and Resolution Experiences
spark调优
只需简单几步 - 开始玩耍微信小程序
Start a business
Qualcomm platform WiFi -- Native crash caused by WiFi
Verilog state machine
el-table的render-header用法
浅谈线程池相关配置
West digital decided to raise the price of flash memory products immediately after the factory was polluted by materials
Halcon image rectification
Use usedeferredvalue for asynchronous rendering
图扑软件通过 CMMI5 级认证!| 国际软件领域高权威高等级认证
/silicosis/geo/GSE184854_ scRNA-seq_ mouse_ lung_ ccr2/GSE184854_ RAW/GSM5598265_ matrix_ inflection_ demult
Verilog 避免 Latch
[road of system analyst] collection of wrong topics in enterprise informatization chapter
Golang configure export goprivate to pull private library code









