当前位置:网站首页>【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 适用于:为了增加代码可读性,且没有很多复杂的关联子查询。
边栏推荐
- PMP是被取消了吗??
- 118. 杨辉三角
- Lean thinking: source, pillar, landing. I understand it after reading this article
- EasyGBS网络不稳定情况下重复请求视频拉流问题的优化
- MySQL common graphics management tools | dark horse programmers
- Facebook聊单,SaleSmartly有妙招!
- The difference between indexof and includes
- Extensive reading of the paper [film: visual reasoning with a general condition layer]
- OpenCV视频质量诊断----视频遮挡诊断
- Dlib+Opencv库实现疲劳检测
猜你喜欢

Les canaux de culture intensive s'efforcent de développer Fu Xin et Wei Shi jiajie pour organiser une conférence de formation sur les nouveaux produits
![Extensive reading of the paper [film: visual reasoning with a general condition layer]](/img/69/f4ba37a7eae34a7e698127c31b0161.png)
Extensive reading of the paper [film: visual reasoning with a general condition layer]

B2B e-commerce platform solution for fresh food industry to improve the standardization and transparency of enterprise transaction process

测试自学人必看:软件测试如何找测试项目?

MATLAB中subplot函数的使用

Summary of SQL query de duplication statistics methods

nacos配置文件发布失败,请检查参数是否正确的解决方案

Getting started with kubernetes command (namespaces, pods)

【Go ~ 0到1 】 第五天 7月1 类型别名,自定义类型,接口,包与初始化函数

SuperVariMag 超导磁体系统 — SVM 系列
随机推荐
MySQL common graphics management tools | dark horse programmers
面试题 16.16. 部分排序-双指针法
[go ~ 0 to 1] day 5 July 1 type alias, custom type, interface, package and initialization function
Solidity - 合约结构 - 错误(error)- ^0.8.4版本新增
Witness the times! "The future of Renji collaboration has come" 2022 Hongji ecological partnership conference opens live broadcast reservation
为什么一定要从DevOps走向BizDevOps?
赋能「新型中国企业」,SAP Process Automation 落地中国
狼人杀攻略:你当我好骗吗,我们相信谁!
新版国标GB28181视频平台EasyGBS如何配置WebRTC视频流格式播放?
Nacos configuration file publishing failed, please check whether the parameters are correct solution
ffmpeg 音频相关命令
Learning notes - steps of JDBC connection database operation
Facebook聊单,SaleSmartly有妙招!
OpenCV视频质量诊断----视频遮挡诊断
More information about M91 fast hall measuring instrument
【To .NET】C#集合类源码解析
PMP是被取消了吗??
微信小程序 navigator点击后有阴影 ,去掉navigator阴影效果
【Go ~ 0到1 】 第四天 6月30 defer,结构体,方法
Solution of digital supply chain centralized purchase platform in mechanical equipment industry: optimize resource allocation and realize cost reduction and efficiency increase