当前位置:网站首页>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 ;
边栏推荐
- 7-2 Finnish wooden chess structure Sorting
- HJ成绩排序
- Tencent continued to lay off staff in the second half of the year, and all business groups reduced by at least 10%. What do you think of this? Followers
- Install haproxy
- Safety training is the greatest benefit for employees! 2022 induction safety training for new employees
- Path alias specified in vite2.9
- Hj21 simple password
- 2021 programming language ranking summary
- flex布局
- Ice - resources
猜你喜欢

Section 5: zynq interrupt

How to configure DDR3 of dm8148

Section 9: dual core startup of zynq

Spark 离线开发框架设计与实现

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

Recommended system series (Lecture 5): Optimization Practice of sorting model

Static resource compression reduces bandwidth pressure and increases access speed

Practice of traffic recording and playback in vivo

Mysql57 zip file installation

kubelet驱逐机制的源码分析
随机推荐
HJ string sort
The solution of "user account control to continue, please enter administrator user name and password" appears in win10 Professional Edition
What is the lifecycle of automated testing?
HJ字符串排序
Porting ucosiii to stm32f429
Disposition Flex
股票炒股注册开户靠谱吗?安全吗?
自动化测试的生命周期是什么?
Sentinel mechanism of redis cluster
flex布局
No suspense about the No. 1 Internet company overtime table
推荐系统系列精讲(第五讲): 排序模型的调优实践
Application of XOR. (extract the rightmost 1 in the number, which is often used in interviews)
Section VII starting principle and configuration of zynq
云原生(待更新)
kubelet驱逐机制的源码分析
8 张图 | 剖析 Eureka 的首次同步注册表
HJ整数与IP地址间的转换
在idea中,get和set方法爆红可能是没有安装Lombok插件
2021 programming language ranking summary