当前位置:网站首页>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
边栏推荐
- Determine whether the linked list is a palindrome linked list
- Gaussdb (for MySQL):partial result cache, which accelerates the operator by caching intermediate results
- 【Kotlin】高阶函数介绍
- 在MeterSphere接口测试中如何使用JMeter函数和MockJS函数
- China benzene hydrogenation Market Research and investment forecast report (2022 Edition)
- Jojogan practice
- 嗨 FUN 一夏,与 StarRocks 一起玩转 SQL Planner!
- Research and investment strategy report of hydroxypropyl beta cyclodextrin industry in China (2022 Edition)
- 判断一棵二叉树是否为平衡二叉树
- Gold, silver and four want to change jobs, so we should seize the time to make up
猜你喜欢

sql刷题586. 订单最多的客户

Shenyu gateway development: enable and run locally

Today, at 14:00, 15 ICLR speakers from Hong Kong University, Beihang, Yale, Tsinghua University, Canada, etc. continue!

String类

PR basic clip operation / video export operation

【C语言基础】12 字符串

Tutorial on the principle and application of database system (003) -- MySQL installation and configuration: manually configure MySQL (Windows Environment)

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

在MeterSphere接口测试中如何使用JMeter函数和MockJS函数

The amazing open source animation library is not only awesome, but also small
随机推荐
拼接字符串,得到字典序最小的结果
你还在用收费的文档管理工具?我这有更牛逼的选择!完全免费
GameFramework食用指南
Soft test software designer full truth simulation question (including answer analysis)
【C补充】【字符串】按日期排序显示一个月的日程
Graduation season | Huawei experts teach the interview secret: how to get a high paying offer from a large factory?
Flux d'entrées / sorties et opérations de fichiers en langage C
mysql -- explain性能优化
荣威 RX5 的「多一点」产品策略
Free lottery | explore the future series of blind box digital copyright works of "abadou" will be launched on the whole network!
剑指 Offer II 015. 字符串中的所有变位词
Advantages, values and risks of chain games compared with traditional games
6月刊 | AntDB数据库参与编写《数据库发展研究报告》 亮相信创产业榜单
模板引擎Velocity 基礎
[jetsonnano] [tutorial] [introductory series] [III] build tensorflow environment
Gold, silver and four want to change jobs, so we should seize the time to make up
P2893 [USACO08FEB] Making the Grade G(dp&优先队列)
Cookies and session keeping technology
Judge whether a binary tree is a balanced binary tree
Leetcode 216 combined summation III -- backtracking method