当前位置:网站首页>【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 适用于:为了增加代码可读性,且没有很多复杂的关联子查询。
边栏推荐
猜你喜欢

混沌工程平台 ChaosBlade-Box 新版重磅发布

nacos启动失败问题解决与总结

新版国标GB28181视频平台EasyGBS如何配置WebRTC视频流格式播放?

kubernetes命令入门(namespaces,pods)

正则表达式=Regex=regular expression

Dom4J解析XML、Xpath检索XML

What must be done in graduation season before going to Shanhai

精耕渠道共谋发展 福昕携手伟仕佳杰开展新产品培训大会

Introduction to relevant processes and functions of wechat official account development

Solution of digital supply chain centralized purchase platform in mechanical equipment industry: optimize resource allocation and realize cost reduction and efficiency increase
随机推荐
Methods of finding various limits
nacos配置文件发布失败,请检查参数是否正确的解决方案
【Go ~ 0到1 】 第五天 7月1 类型别名,自定义类型,接口,包与初始化函数
Learning notes - steps of JDBC connection database operation
Cdga | if you are engaged in the communication industry, you should get a data management certificate
GetMessage底层机制分析
Dlib+Opencv库实现疲劳检测
求各种极限的方法
[go ~ 0 to 1] day 5 July 1 type alias, custom type, interface, package and initialization function
uni-app商品分类
Dlib+opencv library for fatigue detection
Contos 7 set up SFTP to create users, user groups, and delete users
Lake shore optimag superconducting magnet system om series
Solution and summary of Nacos startup failure
Task: denial of service DOS
Solidity - 合约结构 - 错误(error)- ^0.8.4版本新增
数字化转型企业成功的关键,用数据创造价值
Solidity - 算术运算的截断模式(unchecked)与检查模式(checked)- 0.8.0新特性
Go Language Advanced
Reading the paper [learning to discretely compose reasoning module networks for video captioning]