当前位置:网站首页>SQL common syntax records
SQL common syntax records
2022-07-05 21:22:00 【coder chen】
with … as … select
- Writing SQL when , For two already order by Statement of union When the failure , Later it was found in Oracle sql in , requirement order by yes select The last statement of the statement , And one select Only one... Is allowed in the statement order by sentence , and order by Must be located throughout select At the end of the sentence .
- union The operation actually does two parts : Result set merge + Sort ,
- union all Simply merge result sets , Do not sort , Efficient than union high
- Therefore use with … as … select
with
s1 as (select * from table1 t1 order by t1. c1 ),
s2 as ( select * from table1 t2 order by t2.c1 )
select * from s1 union all ( Here can be replaced by union ) select * from s2
Refer to this :https://www.icode9.com/content-2-602860.html
- Yes with … as …select Explanation :
It's actually a lot of things that are used repeatedly sql Put the sentence in with as Inside , Take an alias , Later queries can use it , In this way, for large quantities of sql Statement plays an optimization role , And it's clear
with as Equivalent to virtual view
Refer to this :https://www.cnblogs.com/mingforyou/p/8295239.html
case when
- CASE WHEN Conditional expression function : similar JAVA Medium IF ELSE sentence
CASE WHEN SCORE = 'A' THEN ' optimal '
WHEN SCORE = 'B' THEN ' good '
WHEN SCORE = 'C' THEN ' in ' ELSE ' fail, ' END
Refer to this article :https://blog.csdn.net/rongtaoup/article/details/82183743
group by ,where,having
group by ,where and having Can be used at the same time , But should pay attention to SQL Execution order of ,where>group by>having>select, Can't be in where Queries only after adding groups
https://deepinout.com/sql/sql-dql/sql-select-group-by.html
exists
sql recursive ?
sql Execution order
A complete sql The order of execution is :
- FROM Clause assembly data ( Including passage ON Connect );
- WHERE Clause ;
- GROUP BY grouping ;
- Using aggregate functions to calculate ;
- HAVING Filter groups ;
- Calculate all expressions ;
- SELECT Field of ;
- ORDER BY Sort ;
- LIMIT Screening
sql The two orders of :
Writing order
select … from … where … group by … having … order by …
Execution order
from>where>group by>having>select Field of >distinct>order by>limit
sql Perform principle analysis :https://deepinout.com/sql/sql-dql/sql-select-statement-execution-order.html
distinct explain
DISTINCT Need to precede all column names , If written SELECT name, DISTINCT attack_range FROM heros Will report a mistake .
DISTINCT In fact, it is to de duplicate the combination of all the following column names
not in Failure problem oracle
reason :not in There is null, Need to put null Get rid of
DBLink : It is mainly used for cross database connection query
https://help.aliyun.com/document_detail/99941.html
Use :
establish DBLink
CREATE PUBLIC DATABASE link dblink CONNECT TO user name IDENTIFIED BY password USING ‘ service ip/serviceName’;
Inquire about Current library Of dblink
select * from dba_db_links;
Delete the dblink
DROP PUBLIC DATABASE LINK name (dblink name );
Then pay attention to the cross database joint table Add @dblink name
update [email protected] A set A.user_ORGID =(select B.ORGID from ORG_EMPLOYEE B where B.EMPID=A.EMPID)
Condition query null value judgment
where Keyword followed by manager is not null perhaps manager is null
order by Chinese sort and null sort
https://deepinout.com/sql/sql-dql/sql-select-order-by.html
Common functions
nvl()
It is a null conversion function ,nvl( expression 1, expression 2), If the expression 1 The value of is empty ,nvl The return value is the expression 2 Value , Otherwise return the expression 1 Value .
The value of an expression can be numeric , Character type and date type ,DNA The data type must be consistent .
边栏推荐
- Teach yourself to train pytorch model to Caffe (I)
- 123456
- Golang(1)|从环境准备到快速上手
- 校招期间 准备面试算法岗位 该怎么做?
- 树莓派4B上ncnn转换出来的模型调用时总是崩溃(Segment Fault)的原因
- leetcode:1139. The largest square bounded by 1
- Clion-MinGW编译后的exe文件添加ico图标
- Aitm2-0002 12s or 60s vertical combustion test
- Pytoch practice -- MNIST dataset handwritten digit recognition
- LeetCode_哈希表_困难_149. 直线上最多的点数
猜你喜欢

Reading and writing operations of easyexcel

Enclosed please find. Net Maui's latest learning resources

How to send samples when applying for BS 476-7 display? Is it the same as the display??

Write an interface based on flask

Cross end solution to improve development efficiency rapidly

MQ----activeMq

Zhang Lijun: la pénétration de l’incertitude dépend de quatre « invariants»

基于 Ingress Controller 在集群外访问 Zadig 自测环境(最佳实践)

基於flask寫一個接口
![[case] Application of positioning - Taobao rotation map](/img/2d/c834ce95a2c8e53a20e67fa2e99439.png)
[case] Application of positioning - Taobao rotation map
随机推荐
postgres 建立连接并删除记录
EN 438-7建筑覆盖物装饰用层压板材产品—CE认证
123456
Haas506 2.0 development tutorial - Alibaba cloud OTA - PAC firmware upgrade (only supports versions above 2.2)
Influence of oscilloscope probe on signal source impedance
Access Zadig self-test environment outside the cluster based on ingress controller (best practice)
Aitm2-0002 12s or 60s vertical combustion test
事项研发工作流全面优化|Erda 2.2 版本如“七”而至
Realize the function of verifying whether the user has completed login when browsing the page
Dictionary tree simple introductory question (actually blue question?)
Objects in the list, sorted by a field
EasyExcel的讀寫操作
【日常训练--腾讯精选50】89. 格雷编码(看题解才会的)
面试官:并发编程实战会吗?(线程控制操作详解)
Golang (1) | from environmental preparation to quick start
WPF gets the control in the datagridtemplatecolumn of the specified row and column in the DataGrid
第05章_存储引擎
Arcgis\qgis no plug-in loading (no offset) mapbox HD image map
Careercup its 1.8 serial shift includes problems
字典树简单入门题(居然是蓝题?)