当前位置:网站首页>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
边栏推荐
- 今天14:00 | 港大、北航、耶鲁、清华、加大等15位ICLR一作讲者精彩继续!
- Judge whether the binary tree is a binary search tree
- Flux d'entrées / sorties et opérations de fichiers en langage C
- 智能运维实战:银行业务流程及单笔交易追踪
- Gaussdb (for MySQL):partial result cache, which accelerates the operator by caching intermediate results
- 【C语言补充】判断明天是哪一天(明天的日期)
- Graduation season | Huawei experts teach the interview secret: how to get a high paying offer from a large factory?
- 挖财学堂班主任给的证券账户安全吗?能开户吗?
- Redis6.0 new features
- 如何写出好代码 — 防御式编程指南
猜你喜欢

【PyG】文档总结以及项目经验(持续更新
![[live broadcast appointment] database obcp certification comprehensive upgrade open class](/img/50/83a533f4e8a60f90e03b991385c08d.jpg)
[live broadcast appointment] database obcp certification comprehensive upgrade open class

智能运维实战:银行业务流程及单笔交易追踪

Graduation season | Huawei experts teach the interview secret: how to get a high paying offer from a large factory?

VMware virtual machine failed during startup: VMware Workstation is incompatible with hyper-v
荣威 RX5 的「多一点」产品策略
![[jetsonnano] [tutorial] [introductory series] [III] build tensorflow environment](/img/0e/52e37527bc717c7a55741725087bad.png)
[jetsonnano] [tutorial] [introductory series] [III] build tensorflow environment

可迭代对象与迭代器、生成器的区别与联系

博睿数据一体化智能可观测平台入选中国信通院2022年“云原生产品名录”

巴比特 | 元宇宙每日必读:奈雪币、元宇宙乐园、虚拟股票游戏...奈雪的茶这波“操作拉满”的营销活动你看懂了吗?...
随机推荐
Leetcode records - sort -215, 347, 451, 75
AI高考志愿填报:大厂神仙打架,考生付费围观
ACM MM 2022视频理解挑战赛视频分类赛道冠军AutoX团队技术分享
模板引擎Velocity 基础
【直播预约】数据库OBCP认证全面升级公开课
[nodemon] app crashed - waiting for file changes before starting... resolvent
Shenyu gateway development: enable and run locally
Are you still using charged document management tools? I have a better choice! Completely free
Internet News: "20220222" get together to get licenses; Many products of Jimi have been affirmed by consumers; Starbucks was fined for using expired ingredients in two stores
【C語言補充】判斷明天是哪一天(明天的日期)
Research and investment strategy report of China's sodium sulfate industry (2022 Edition)
Judge whether the binary tree is a binary search tree
在MeterSphere接口测试中如何使用JMeter函数和MockJS函数
越来越多地使用 SLO 来实现可观测性|DevOps
Transition technology from IPv4 to IPv6
Determine whether the linked list is a palindrome linked list
Leetcode 216 combined summation III -- backtracking method
Sword finger offer II 015 All modifiers in the string
Machine learning 11 clustering, outlier discrimination
阿里云、追一科技抢滩对话式AI