当前位置:网站首页>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


边栏推荐
- 2022-2028 global aluminum beverage can coating industry research and trend analysis report
- Calculation of page table size of level 2, level 3 and level 4 in protection mode (4k=4*2^10)
- IPhone 6 plus is listed in Apple's "retro products" list
- tarjan2
- ZABBIX API creates hosts in batches according to the host information in Excel files
- 4. Find the median of two positive arrays
- 只需简单几步 - 开始玩耍微信小程序
- Render header usage of El table
- Gradle 笔记
- The capacity is upgraded again, and the new 256gb large capacity specification of Lexar rexa 2000x memory card is added
猜你喜欢

浅谈线程池相关配置

2022-2028 global military computer industry research and trend analysis report

A list of job levels and salaries in common Internet companies. Those who have conditions must enter big factories. The salary is really high

How to create an instance of the control defined in SAP ui5 XML view at runtime?

Golang configure export goprivate to pull private library code

West digital decided to raise the price of flash memory products immediately after the factory was polluted by materials
![寻找重复数[抽象二分/快慢指针/二进制枚举]](/img/9b/3c001c3b86ca3f8622daa7f7687cdb.png)
寻找重复数[抽象二分/快慢指针/二进制枚举]

Framing in data transmission

C shallow copy and deep copy

Common means of modeling: aggregation
随机推荐
[C Advanced] brother Peng takes you to play with strings and memory functions
The capacity is upgraded again, and the new 256gb large capacity specification of Lexar rexa 2000x memory card is added
Verilog 避免 Latch
[road of system analyst] collection of wrong topics in enterprise informatization chapter
Global and Chinese market of gynaecological health training manikin 2022-2028: Research Report on technology, participants, trends, market size and share
Missing numbers from 0 to n-1 (simple difficulty)
Render header usage of El table
JS introduction < 1 >
Gradle 笔记
JS <2>
SAML2.0 笔记(一)
Mongodb non relational database
Intersection of Venn graph
Global and Chinese markets for ultrasonic probe disinfection systems 2022-2028: Research Report on technology, participants, trends, market size and share
Mathematical calculation in real mode addressing
GSE104154_scRNA-seq_fibrotic MC_bleomycin/normalized AM3
Screenshot literacy tool download and use
What is hybrid web containers for SAP ui5
Competition and adventure burr
Share the basic knowledge of a common Hongmeng application