当前位置:网站首页>[SQL optimization] the difference between with as and temporary tables
[SQL optimization] the difference between with as and temporary tables
2022-07-01 19:36:00 【Tanyue Jianzhi Dachang】
with as and The difference between temporary tables
1.with as
with as Just treat the subquery statement as a table , But the real data is not inserted into the database , Its advantage is to increase the readability and maintenance of the code .
with tmp_01 as (
select *
from table)
select *
from tmp_01;
2. A temporary table
The data of the temporary table needs to be inserted into the database , So it is generally used for making statements , After inserting data, you need to delete the temporary table .
drop table if exists tmp_01;
create table if not exists tmp_01 as
select *
from table;
select *
from tmp_01;
3. Operational efficiency
use with as , In fact, there is no difference in efficiency with direct sub query ;
The temporary table is similar to the permanent table , The data is really running into the database , Equivalent to the second direct correlation is a small table , Query efficiency is greatly improved .
4. Application scenarios
Temporary table applies to : There are many complex associated sub table queries .
with as Apply to : To increase code readability , And there are not many complex associated sub queries .
边栏推荐
- Chaos engineering platform chaosblade box new heavy release
- Helium transmission line of lake shore cryostat
- torch.nn.functional.interpolate函数
- Basic knowledge of audio coding and decoding
- Lean thinking: source, pillar, landing. I understand it after reading this article
- XML语法、约束
- [go ~ 0 to 1] day 4 June 30 defer, structure, method
- Learning notes [Gumbel softmax]
- 研究了11种实时聊天软件,我发现都具备这些功能…
- A brief understanding of white box encryption technology
猜你喜欢
随机推荐
如何正确使用Vertx操作Redis(3.9.4带源码分析)
wireshark报文分析tcp,ftp
Nat penetration of gb28181
【英语语法】Unit1 冠词、名词、代词和数词
[pytorch record] automatic hybrid accuracy training torch cuda. amp
How to redraw the header of CListCtrl in MFC
微信公众号开发相关流程及功能介绍
【6.24-7.1】写作社区精彩技术博文回顾
EasyGBS主子码流都为H.265时,切换出现花屏如何解决?
Dom4J解析XML、Xpath检索XML
Extensive reading of the paper [film: visual reasoning with a general condition layer]
正则表达式=Regex=regular expression
pickle.load报错【AttributeError: Can‘t get attribute ‘Vocabulary‘ on <module ‘__main__‘】
博途V16 获取系统时间转换成字符串
Opencv video quality diagnosis - VIDEO occlusion diagnosis
Facebook聊单,SaleSmartly有妙招!
AAAI2020: Real-time Scene Text Detection with Differentiable Binarization
Learning records of building thingsboard, an Internet of things platform
Basic knowledge of audio coding and decoding
【Go ~ 0到1 】 第四天 6月30 defer,结构体,方法









