当前位置:网站首页>【sql优化】with as 和 临时表的区别
【sql优化】with as 和 临时表的区别
2022-07-01 18:45:00 【檀越剑指大厂】
with as 和 临时表的区别
1.with as
with as 只是把子查询的语句当作了一个表,但是真实的数据并没有插入到数据库,它的好处是增加了代码的可读性和进行维护。
with tmp_01 as (
select *
from table)
select *
from tmp_01;
2. 临时表
临时表的数据是需要插入到数据库的,所以一般用于做报表的话,在插入数据之后需要删除临时表。
drop table if exists tmp_01;
create table if not exists tmp_01 as
select *
from table;
select *
from tmp_01;
3. 运行效率
用 with as , 其实跟直接用子查询效率上没有什么区别;
而用临时表与永久表相似,数据是真是跑入到数据库里面去的,相当于第二次直接关联的是一个小表,查询效率大大提高。
4. 应用场景
临时表适用于:有很多复杂的关联子表查询。
with as 适用于:为了增加代码可读性,且没有很多复杂的关联子查询。
边栏推荐
- Native JS creates a calendar - supports mouse wheel scrolling to select months - and can be ported to any framework
- DTD建模
- Transform + ASM data
- 【To .NET】C#集合类源码解析
- 论文泛读【FiLM: Visual Reasoning with a General Conditioning Layer】
- SuperVariMag 超导磁体系统 — SVM 系列
- Solidity - truncated and checked modes of arithmetic operations - new features of 0.8.0
- Superoptimag superconducting magnet system - SOM, Som2 series
- 物联网平台thingsboard搭建学习记录
- 703. 数据流中的第 K 大元素
猜你喜欢
Introduction to relevant processes and functions of wechat official account development
使用环信提供的uni-app Demo,快速实现一对一单聊
PMP是被取消了吗??
为什么一定要从DevOps走向BizDevOps?
Reading the paper [learning to discretely compose reasoning module networks for video captioning]
Dom4j parsing XML, XPath retrieving XML
求各种极限的方法
Detailed explanation of JUnit unit test framework
nacos启动失败问题解决与总结
宝,运维100+服务器很头疼怎么办?用行云管家!
随机推荐
Once the SQL is optimized, the database query speed is increased by 60 times
[pytorch record] distributed training dataparallel and distributeddataparallel of the model
ffmpeg常用命令(二)
English语法_形容词/副词3级 -注意事项
见证时代!“人玑协同 未来已来”2022弘玑生态伙伴大会开启直播预约
Ubuntu14 install MySQL and configure root account local and remote access
IPv4地址、子网掩码、网关
Is PMP cancelled??
The difference between indexof and includes
How to redraw the header of CListCtrl in MFC
精耕渠道共謀發展 福昕攜手偉仕佳傑開展新產品培訓大會
原生js打造日程表-支持鼠标滚轮滚动选择月份-可以移植到任何框架中
正则表达式=Regex=regular expression
ECS summer money saving secret, this time @ old users come and take it away
【pytorch记录】模型的分布式训练DataParallel、DistributedDataParallel
精耕渠道共谋发展 福昕携手伟仕佳杰开展新产品培训大会
Lumiprobe phosphide hexaethylene phosphide specification
Digital business cloud: from planning to implementation, how does Minmetals Group quickly build a new pattern of digital development?
Write it down once Net travel management background CPU Explosion Analysis
使用环信提供的uni-app Demo,快速实现一对一单聊