当前位置:网站首页>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
边栏推荐
- sql刷题584. 寻找用户推荐人
- 免费抽奖 | 《阿巴豆》探索未来系列盲盒数字版权作品全网首发!
- [C language foundation] 12 strings
- Girls who want to do software testing look here
- Hidden Markov model (HMM): model parameter estimation
- 【Kotlin】高阶函数介绍
- 换掉UUID,NanoID更快更安全!
- How to use etcd to realize distributed /etc directory
- Cookies and session keeping technology
- Activity的生命周期和启动模式详解
猜你喜欢
如何写出好代码 — 防御式编程指南
How to repair the laptop that cannot connect to the wireless network
Alibaba cloud, Zhuoyi technology beach grabbing dialogue AI
【C语言基础】12 字符串
免费抽奖 | 《阿巴豆》探索未来系列盲盒数字版权作品全网首发!
Iommu/smmuv3 code analysis (10) page table operation
美国国家安全局(NSA)“酸狐狸”漏洞攻击武器平台技术分析报告
想做软件测试的女孩子看这里
Redis 分布式鎖
多线程并发之CountDownLatch阻塞等待
随机推荐
China carbon disulfide industry research and investment strategy report (2022 Edition)
越来越多地使用 SLO 来实现可观测性|DevOps
redis -- 数据类型及操作
【C語言補充】判斷明天是哪一天(明天的日期)
在MeterSphere接口测试中如何使用JMeter函数和MockJS函数
6月刊 | AntDB数据库参与编写《数据库发展研究报告》 亮相信创产业榜单
Rhcsa Road
Gold, silver and four want to change jobs, so we should seize the time to make up
Free lottery | explore the future series of blind box digital copyright works of "abadou" will be launched on the whole network!
存在安全隐患 起亚召回部分K3新能源
Cookies and session keeping technology
Alibaba cloud, Zhuoyi technology beach grabbing dialogue AI
Redis distributed lock
Template Engine Velocity Foundation
How to solve the keyboard key failure of notebook computer
今天14:00 | 港大、北航、耶鲁、清华、加大等15位ICLR一作讲者精彩继续!
P2592 [ZJOI2008]生日聚会(dp)
How to solve the problem that the battery icon of notebook computer does not display
What are the differences between PHP and DW
换掉UUID,NanoID更快更安全!