1 多个临时表的用法
WITH ttx AS (SELECT * FROM tt),
ttx1 AS (SELECT * FROM tt1)
SELECT * FROM ttx ,ttx1;
2 这个可以省掉用ddl建表语句了
with test as (
select '1' id,'111' col1 ,'1234' col2 from dual union all
select '1' id,'222' col1 ,'1234' col2 from dual union all
select '1' id,'111' col1 ,'3456' col2 from dual union all
select '2' id,'111' col1 ,'345' col2 from dual union all
select '2' id,'222' col1 ,'345' col2 from dual union all
select '2' id,'222' col1 ,'322' col2 from dual)
select * from test a where (id,col2) in (select id,col2 from test b where b.col1<>a.col1)
本文介绍了如何使用WITH子句创建临时表来简化SQL查询过程。通过示例展示了如何利用临时表进行数据筛选和联表操作,避免了繁琐的DDL建表步骤,提高了查询效率。
5498

被折叠的 条评论
为什么被折叠?



