当前位置:网站首页>[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 .
边栏推荐
猜你喜欢

Interview questions for audio and video positions in Dachang -- today's headline

微信公众号开发相关流程及功能介绍

Case sharing: basic networking configuration of QinQ

Introduction and installation of crunch, and making password dictionary with crunch

奔赴山海之前,毕业季一定要做的那些事情

Solidity - contract structure - error - ^0.8.4 NEW

商业智能BI开发和报表开发有什么本质区别?

wireshark报文分析tcp,ftp

uni-app商品分类

论文泛读【FiLM: Visual Reasoning with a General Conditioning Layer】
随机推荐
ECS summer money saving secret, this time @ old users come and take it away
[pytorch record] automatic hybrid accuracy training torch cuda. amp
Go语言高级
AAAI2020: Real-time Scene Text Detection with Differentiable Binarization
原生js打造日程表-支持鼠标滚轮滚动选择月份-可以移植到任何框架中
241. Different Ways to Add Parentheses
[go ~ 0 to 1] day 4 June 30 defer, structure, method
GetMessage底层机制分析
optaplanner学习笔记(一)案例Cloud balance
【To .NET】C#集合类源码解析
H264编码profile & level控制
新版国标GB28181视频平台EasyGBS如何配置WebRTC视频流格式播放?
ffmpeg 错误码
Witness the times! "The future of Renji collaboration has come" 2022 Hongji ecological partnership conference opens live broadcast reservation
Audio and video, encoding and decoding related e-books, gadgets, packaged for free!
XML语法、约束
241. Different Ways to Add Parentheses
What must be done in graduation season before going to Shanhai
求各种极限的方法
A brief understanding of white box encryption technology