只知道用with cte as提高性能,具体的理论可以看看这篇文章
https://blog.csdn.net/weixin_34273479/article/details/94137701
--首先是with cte 的用法
--其实在我的理解中with cte就是生成一张临时的虚拟的表
--语法如下:----------------------------------------------------
with 随便什么名字 as
(
--查询的sql语句
select * from tableA
)
--两个with cte如下:------------------------------------------------
with tableA as
(
select Fil1,Fil2,Fil3,Fil4 as times from TableName
)
,tableB as
(
select * from TableName
)
--把with当做子查询----------------------------------------------------
with tableA as
(
select id as times from TableName
)
select * from tableB where id in(select * from tableA)
--利用with把查询到的数据插入到另一张表中-------------------------------
with tableA as
(
select FilA1,FilA2,FilA3,FilA4 as times from TableName
)
INSERT INTO 插入表的表名
(FilB1,FilB2,FilB3,FilB4)
select * from tableA