当前位置:网站首页>[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 .
边栏推荐
- 如何正确使用Vertx操作Redis(3.9.4带源码分析)
- 【To .NET】C#集合类源码解析
- pickle. Load error [attributeerror: can't get attribute 'volatile' on < module '\u main']
- Go Language Advanced
- 博途V16 获取系统时间转换成字符串
- Write it down once Net travel management background CPU Explosion Analysis
- Learning notes - steps of JDBC connection database operation
- CMU AI PhD 第一年总结
- The use of subplot function in MATLAB
- 【英语语法】Unit1 冠词、名词、代词和数词
猜你喜欢
MySQl的基本使用
Extensive reading of the paper [film: visual reasoning with a general condition layer]
白盒加密技术浅理解
Solidity - 合约结构 - 错误(error)- ^0.8.4版本新增
XML语法、约束
Summary of SQL query de duplication statistics methods
Instagram 为何从内容共享平台变成营销工具?独立站卖家如何利用该工具?
EasyGBS主子码流都为H.265时,切换出现花屏如何解决?
Introduction and installation of crunch, and making password dictionary with crunch
Nacos configuration file publishing failed, please check whether the parameters are correct solution
随机推荐
[to.Net] C set class source code analysis
Ubuntu14 install MySQL and configure root account local and remote access
求各种极限的方法
Nacos configuration file publishing failed, please check whether the parameters are correct solution
赋能「新型中国企业」,SAP Process Automation 落地中国
Audio and video, encoding and decoding related e-books, gadgets, packaged for free!
直播HLS协议
PostgreSQL varchar[] array type operation
Lean thinking: source, pillar, landing. I understand it after reading this article
[English grammar] Unit1 articles, nouns, pronouns and numerals
[Mori city] random talk on GIS data (I)
Facebook聊单,SaleSmartly有妙招!
EasyGBS网络不稳定情况下重复请求视频拉流问题的优化
Solidity - 合约结构 - 错误(error)- ^0.8.4版本新增
optaplanner学习笔记(一)案例Cloud balance
GB28181之SIP协议
ES6中的代理proxy
Thesis reading [distinctive late semantic graph for video capturing]
使用环信提供的uni-app Demo,快速实现一对一单聊
Task: denial of service DOS