当前位置:网站首页>【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 适用于:为了增加代码可读性,且没有很多复杂的关联子查询。
边栏推荐
- Chinese and English instructions human soluble advanced glycation end products receptor (sRAGE) ELISA Kit
- DTD建模
- Learning records of building thingsboard, an Internet of things platform
- What must be done in graduation season before going to Shanhai
- Three ways for redis to realize current limiting
- 【6.24-7.1】写作社区精彩技术博文回顾
- Parallelism, concurrency and life cycle of threads
- Lake Shore 连续流动低温恒温器传输线
- Boost the development of digital economy and consolidate the base of digital talents - the digital talent competition was successfully held in Kunming
- Detailed explanation of JUnit unit test framework
猜你喜欢

从零开始学 MySQL —数据库和数据表操作

Solidity - contract structure - error - ^0.8.4 NEW

Intensive cultivation of channels for joint development Fuxin and Weishi Jiajie held a new product training conference

uni-app微信小程序一键登录获取权限功能

Native JS creates a calendar - supports mouse wheel scrolling to select months - and can be ported to any framework

Solution and summary of Nacos startup failure
![[go ~ 0 to 1] day 5 July 1 type alias, custom type, interface, package and initialization function](/img/1e/bed6a761f07c052e43b1e3b1701760.png)
[go ~ 0 to 1] day 5 July 1 type alias, custom type, interface, package and initialization function

Solution of intelligent supply chain management platform in aquatic industry: support the digitalization of enterprise supply chain and improve enterprise management efficiency

Lake shore optimag superconducting magnet system om series

商业智能BI开发和报表开发有什么本质区别?
随机推荐
Cdga | if you are engaged in the communication industry, you should get a data management certificate
DTD建模
Enabling "new Chinese enterprises", SAP process automation landing in China
Intensive cultivation of channels for joint development Fuxin and Weishi Jiajie held a new product training conference
宝,运维100+服务器很头疼怎么办?用行云管家!
uni-app商品分类
Solidity - truncated and checked modes of arithmetic operations - new features of 0.8.0
Lake Shore - crx-em-hf low temperature probe station
【pytorch记录】模型的分布式训练DataParallel、DistributedDataParallel
Transform + ASM data
Collation of open source protocols of open source frameworks commonly used in Web Development
【英语语法】Unit1 冠词、名词、代词和数词
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
见证时代!“人玑协同 未来已来”2022弘玑生态伙伴大会开启直播预约
面试题 16.16. 部分排序-双指针法
Summary of SQL query de duplication statistics methods
Lake shore M91 fast hall measuring instrument
狼人杀攻略:你当我好骗吗,我们相信谁!
[go ~ 0 to 1] day 5 July 1 type alias, custom type, interface, package and initialization function
torch.nn.functional.interpolate函数