当前位置:网站首页>Today's notes 22/1/7
Today's notes 22/1/7
2022-06-28 07:43:00 【Zeiyalo】
Learning notes
One 、SQL Priority calculated in the query :
priority : The order of calculation
1. parentheses
2. Multiplication and division
3. Addition and subtraction , Connector
4. Comparison symbol
5.is null,in
6.between and
7.not
8.and
9.or
Parentheses have the highest priority ,or Has the lowest priority
You can use parentheses to change the priority
The same priority is calculated from left to right
If you don't remember the priority order , Remember to put parentheses
((A and B) or (C and D))
((A or (B and C)) or D)
Above transferred from :CSDN Blogger 「Tapyou」 The original article of
Link to the original text :https://blog.csdn.net/Tapyou/article/details/120923932
Two 、SQL The escape problem of fuzzy query in
If we just want to output ‘’&‘’ This ordinary character of , Variables can be used to close (set define off Statement to turn off the substitution variable function ), In this way, we can “&” Output as normal characters , Besides , You can also use ‘/’ perhaps ‘\’ A single special character escape is implemented ;
eg:
Mode one :
set define off;-- Functions of closed substitution variables
Mode two :
select *
from students
where name like '%/&%';
Through the above statement, you can put & Output as normal characters ;
3、 ... and 、SQL conditional ,case when Statements and decode() function Use
1.case when Two ways of using
a. Return the corresponding return value according to the corresponding value ;
case Field name
when Corresponding field value 1 then value 1
when Corresponding field value 2 then value 2
when Corresponding field value 3 then value 3
…
else value N
end
b. Return the corresponding value according to the corresponding condition ;
case
when Conditions 1 then value 1
when Conditions 2 then value 2
when Conditions 3 then value 3
…
else value N
2.decode() Function usage form
decode( Field name , Corresponding value 1, Return value 1, Corresponding value 2, Return value 2,…, Return value N)
The matching value returns the corresponding return value ,else return “ Return value N” This value ;
eg:
case Example :
SELECT E.ENAME,
CASE
WHEN SAL >= 3000 THEN ' Class A '
WHEN SAL >= 2000 THEN ' second level '
WHEN SAL >= 1000 THEN ' Level three '
ELSE ' Level Four '
END Pay scales
FROM EMP E;
decode Function example function :
SELECT E.ENAME,DECODE(DEPTNO, 10, ' Ten departments ', 20, ' Twenty departments ', ' Thirty departments ') Pay scales
FROM EMP E;
Four 、 Link query
1. The first category
Internal connection :
Format :
The left table [inner] join Right table - -[ ] Some of the representations in the can be omitted
on Table join condition
eg:
SELECT
FROM EMP E
JOIN DEPT D
ON E.DEPTNO = D.DEPTNO
The left table is connected with the right table , Keep the data rows that the two tables match according to the table connection conditions , Unmatched data rows deleted .
External connection :
The left outer join :
Format :
The left table left [outer] join Right table
on Table join condition
eg:
SELECT
FROM EMP E
LEFT JOIN DEPT D
ON E.DEPTNO = D.DEPTNO
The left table is connected with the right table , In the new table , Keep the data rows that the two tables match according to the table connection conditions , The data row on the unmatched left table remains , The corresponding data in the right table is null fill , Delete other unmatched data rows ;

Right connection :
Format :
The left table right [outer] join Right table
on Table join condition
Opposite to the left outer connection ;
SELECT
FROM EMP E
RIGHT JOIN DEPT D
ON E.DEPTNO = D.DEPTNO
Full outer join :
Format :
The left table full [outer] join Right table
on Table join condition
SELECT
FROM EMP E
FULL JOIN DEPT D
ON E.DEPTNO = D.DEPTNO
The left table is connected with the right table , In the new table , Keep the data rows that the two tables match according to the table connection conditions , The data row on the unmatched left table remains , The corresponding data in the right table is null fill , The data row on the unmatched right table is also reserved , The corresponding data in the left table is represented by null fill .

summary :
In my current understanding, the operation of table connection is to connect two tables according to on The following table join conditions combine the two tables into one table ;
The inner connection is to keep only the data rows on the match ;
The left outer join is the data row reservation on the unmatched left table , The data row of the right table is not reserved ;
The right outer join is the data row reservation on the unmatched right table , The data row of the left table is not reserved ;
All external connections are reserved for both matched and unmatched data ;
Unmatched data rows reserved by the outer connection , The remainder is filled with null values ;
5、 ... and 、 Intersection and complement in SQL Application in
For the intersection and complement set learned before, it can also be used for SQL Table in , Using it in conjunction with the join operation has something new to look at ;
eg: Full outer join minus Right connection
effect : Get the unique data in the left table , That is, keep the unmatched data rows in the left table , The data in the right table is filled with null values :
(SELECT *
FROM EMP E
FULL JOIN DEPT D
ON E.DEPTNO = D.DEPTNO
) MINUS (
SELECT *
FROM EMP E
JOIN DEPT D
ON E.DEPTNO = D.DEPTNO
);
In addition to the above methods , There are other ways to get the data in the left table , Consider using the left outer connection minus The operation of fetching the unique data in the left table is performed by internal connection , Because the code content is similar , Don't type the code here ;
边栏推荐
- Installing redis on Linux
- Application of XOR. (extract the rightmost 1 in the number, which is often used in interviews)
- 一个小工具可以更快的写爬虫
- ABAP skill tree
- HJ string sort
- 推荐系统系列精讲(第五讲): 排序模型的调优实践
- 异或的应用。(提取出数字中最右侧的1,面试中经常用的到)
- Kubelet garbage collection (exiting containers and unused images) source code analysis
- Hack the box:routerspace
- 阿里云服务器创建快照、回滚磁盘
猜你喜欢

Introduction and several months' experience of extending the solution thanos of Prometheus

Kubernetes理论基础

Online WPS tool

Disposition Flex

Kubernetes cluster command line tool kubectl

Kubelet garbage collection (exiting containers and unused images) source code analysis

GoLand IDE and delve debug Go programs in kubernetes cluster

Porting ucosiii to stm32f429
![[ thanos源码分析系列 ]thanos query组件源码简析](/img/e4/2a87ef0d5cee0cc1c1e1b91b6fd4af.png)
[ thanos源码分析系列 ]thanos query组件源码简析

Practice and exploration of vivo live broadcast application technology
随机推荐
Can okcc call centers work without computers?
ACM笔记
Recommended system series (Lecture 5): Optimization Practice of sorting model
pip 更新到最新的版本
kubernetes删除pod的流程的源码简析
本周二晚19:00战码先锋第8期直播丨如何多方位参与OpenHarmony开源贡献
Source code analysis of kubernetes' process of deleting pod
Is it reliable to open a new bond registration account? Is it safe?
Sentinel mechanism of redis cluster
Understanding of OPC protocol
Es data export CSV file
Drawing animated bubble chart with R language
Solving the longest palindrome substring by dynamic programming
HJ明明的随机数
自动化测试的生命周期是什么?
Conversion between HJ integer and IP address
Practice of traffic recording and playback in vivo
HJ score ranking
Kubernetes theoretical basis
HJ删除字符串中出现次数最少的字符