当前位置:网站首页>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
边栏推荐
- tarjan2
- 数据传输中的成帧
- Jointly developed by nailing, the exclusive functions of glory tablet V7 series were officially launched
- ORA-01547、ORA-01194、ORA-01110
- 命名块 verilog
- 2022 hoisting machinery command examination paper and summary of hoisting machinery command examination
- 2022-2028 global wood vacuum coating machine industry research and trend analysis report
- GB/T-2423. XX environmental test documents, including the latest documents
- Delphi xe10.4 installing alphacontrols15.12
- ZABBIX API creates hosts in batches according to the host information in Excel files
猜你喜欢
MMSegmentation系列之训练与推理自己的数据集(三)
ZABBIX API creates hosts in batches according to the host information in Excel files
Start a business
Form custom verification rules
Missing numbers from 0 to n-1 (simple difficulty)
Detailed explanation of the difference between Verilog process assignment
Share the basic knowledge of a common Hongmeng application
2022-2028 global wood vacuum coating machine industry research and trend analysis report
Just a few simple steps - start playing wechat applet
[staff] pitch representation (bass clef | C1 36 note pitch representation | C2 48 note pitch representation | C3 60 note pitch representation)
随机推荐
终日乾乾,夕惕若厉
Go执行shell命令
Qualcomm platform WiFi -- Native crash caused by WiFi
Delphi xe10.4 installing alphacontrols15.12
venn圖取交集
C # joint halcon out of halcon Environment and various Error Reporting and Resolution Experiences
Sentry experience and architecture, a fledgling monitoring product with a market value of $100million
2022-2028 global human internal visualization system industry research and trend analysis report
Work hard all day long and be alert at sunset
Addition without addition, subtraction, multiplication and division (simple difficulty)
Missing numbers from 0 to n-1 (simple difficulty)
高并发场景下缓存处理方案
Continuous assignment of Verilog procedure
Stdref and stdcref
Verilog 避免 Latch
[JVM] detailed description of the process of creating objects
Uniapp uses canvas to generate posters and save them locally
Jointly developed by nailing, the exclusive functions of glory tablet V7 series were officially launched
The capacity is upgraded again, and the new 256gb large capacity specification of Lexar rexa 2000x memory card is added
32, 64, 128 bit system