sql 使用with构建临时表

with x as
(
select 1 as id ,'Adam' as name from dual  union all
select 2 as id ,'John' as name from dual
)
select * from x

这样就构造了一个由两行组成的临时表

 

 

如果需要构造临时表来表示表间关系

with a as (select 1 as id from dual union all select 2 as id from dual) , 
     b as (select 1 as id,'Adam' as name from dual union all select 3 as id,'Tom' as name from dual)
select a.id,b.name from a left join b on a.id=b.id

使用逗号 来表示两表并列,就可以构造两个临时表了。

posted @ 2021-01-26 11:21  一年变大牛  阅读(3030)  评论(0编辑  收藏  举报