当前位置:网站首页>Mysql database - Advanced SQL statement (2)
Mysql database - Advanced SQL statement (2)
2022-07-01 16:58:00 【Seal nine FJ】
MySQL Union set 、 Intersection value 、 No intersection value 、case
1. 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
1)UNION

2)UNION ALL

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

- There are no duplicate rows in the two tables , And when there are intersections, use

- 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

Null value (NULL) and No value (’’) The difference between
- Null value length is 0, Does not occupy a space
- NULL The length of the value is null, Occupancy space
- is null Cannot determine null value
- Null use “=” perhaps “<>” To deal with it
- count() When calculating ,NULL Will be ignored , Null values are added to the calculation


MySQL Regular expressions of

stored procedure
1. brief introduction
- MysQL A database stored procedure is a set of procedures designed to perform specific functions SQL Collection of statements
- The function of stored procedure is from 5.0 The version just started to support , It can speed up database processing , Enhance the flexibility of database in practical application
- 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
- The traditional method of operating a database SQL The statement needs to be compiled before execution , Then go ahead and do it , Compare with stored procedures , Obviously, stored procedures are faster to execute , More efficient
2. advantage
- 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 )

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

Sort

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


- Add extra :
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
边栏推荐
- 如何写出好代码 — 防御式编程指南
- Building blocks for domestic databases, stonedb integrated real-time HTAP database is officially open source!
- How to use etcd to realize distributed /etc directory
- Redis distributed lock
- Introduction to software engineering - Chapter 6 - detailed design
- 越来越多地使用 SLO 来实现可观测性|DevOps
- Machine learning 11 clustering, outlier discrimination
- Basic use of MySQL
- Pytest learning notes (13) -allure of allure Description () and @allure title()
- C語言輸入/輸出流和文件操作
猜你喜欢

What is the effect of choosing game shield safely in the game industry?

Leetcode records - sort -215, 347, 451, 75

你还在用收费的文档管理工具?我这有更牛逼的选择!完全免费

Template engine velocity Foundation

Girls who want to do software testing look here

Are you still using charged document management tools? I have a better choice! Completely free

游戏行业安全选择游戏盾,效果怎么样?

免费抽奖 | 《阿巴豆》探索未来系列盲盒数字版权作品全网首发!

ACM MM 2022视频理解挑战赛视频分类赛道冠军AutoX团队技术分享

走进微信小程序
随机推荐
National Security Agency (NSA) "sour Fox" vulnerability attack weapon platform technical analysis report
SystemVerilog structure (II)
Installation and use of sqoop
重磅披露!上百个重要信息系统被入侵,主机成为重点攻击目标
Redis6.0 new features
Exclusive news: Alibaba cloud quietly launched RPA cloud computer and has opened cooperation with many RPA manufacturers
Sword finger offer II 015 All modifiers in the string
SQL question brushing 1050 Actors and directors who have worked together at least three times
VMware virtual machine failed during startup: VMware Workstation is incompatible with hyper-v
判断链表是否是回文链表
C語言輸入/輸出流和文件操作
独家消息:阿里云悄然推出RPA云电脑,已与多家RPA厂商开放合作
今天14:00 | 港大、北航、耶鲁、清华、加大等15位ICLR一作讲者精彩继续!
越来越多地使用 SLO 来实现可观测性|DevOps
How to maintain the laptop battery
Babbitt | yuan universe daily must read: Naixue coin, Yuan universe paradise, virtual stock game Do you understand Naixue's tea's marketing campaign of "operation pull full"
Are you still using charged document management tools? I have a better choice! Completely free
Alibaba cloud, Zhuoyi technology beach grabbing dialogue AI
中国锦纶长丝缝纫线发展预测与投资方向研究报告(2022版)
【C补充】【字符串】按日期排序显示一个月的日程