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


边栏推荐
- OSPF LSA message parsing (under update)
- buu_ re_ crackMe
- Verilog 过程赋值 区别 详解
- Verilog 状态机
- Global and Chinese market of bone adhesives 2022-2028: Research Report on technology, participants, trends, market size and share
- Tupu software has passed CMMI5 certification| High authority and high-level certification in the international software field
- Jointly developed by nailing, the exclusive functions of glory tablet V7 series were officially launched
- Qualcomm platform WiFi -- Native crash caused by WiFi
- Continuous assignment of Verilog procedure
- Unit · elementary C # learning notes
猜你喜欢
![[staff] pitch representation (bass clef | C1 36 note pitch representation | C2 48 note pitch representation | C3 60 note pitch representation)](/img/98/956d8abbccceb1aae47e25825bc63d.jpg)
[staff] pitch representation (bass clef | C1 36 note pitch representation | C2 48 note pitch representation | C3 60 note pitch representation)

SAML2.0 笔记(一)

Verilog state machine

Discussion on related configuration of thread pool

创业了...

Verilog avoid latch

QT environment generates dump to solve abnormal crash

Actual battle of financial risk control - under Feature Engineering

Verilog 避免 Latch

Soul app released the annual report on generation Z behavior: nearly 20% of young people love shopping in the vegetable market
随机推荐
GSE104154_scRNA-seq_fibrotic MC_bleomycin/normalized AM3
Just a few simple steps - start playing wechat applet
OSPF LSA message parsing (under update)
PHP notes - use Smarty to set public pages (include, if, else, variable settings)
Verilog avoid latch
spark调优
PHP array processing
竞争与冒险 毛刺
自定义组件的 v-model
Verilog 避免 Latch
Verilog 过程连续赋值
[JVM] detailed description of the process of creating objects
Missing numbers from 0 to n-1 (simple difficulty)
SAML2.0 notes (I)
[staff] pitch representation (bass clef | C1 36 note pitch representation | C2 48 note pitch representation | C3 60 note pitch representation)
Load different fonts in QML
Intersection of Venn graph
Use usedeferredvalue for asynchronous rendering
终日乾乾,夕惕若厉
流线线使用阻塞还是非阻塞