ITPub博客

首页 > Linux操作系统 > Linux操作系统 > with as

with as

原创 Linux操作系统 作者:Aminiy 时间:2013-09-02 21:03:53 0 删除 编辑
今天在网上查找优化的案例,碰巧在一个大神的博客里看到这个用法了,起初还很疑惑,所以就跟着做了下实验:
SQL> create table t2(id int); 
Table created.

SQL> create table t1(id int); 

Table created.

SQL> insert into t2 values(1);

1 row created.

SQL> insert into t2 values(2);

1 row created.

SQL> insert into t2 values(3);

1 row created.

SQL> insert into t1 values(1);

1 row created.
SQL> select * from t1;

        ID
----------
         1

SQL> select * from t2;

        ID
----------
         1
         2
         3
SQL> with a as (select * from t1),
  2   b as (select * from t2)
  3  select * from t2
  4  union
  5  select * from t1;

        ID
----------
         1
         2
         3

SQL> with a as (select * from t1),
  2  b as (select * from t2)
  3  select * from a
  4  union
  5  select * from b; 

        ID
----------
         1
         2
         3
SQL> with a as (select * from t1),
  2  b as (select * from t2)
  3  select * from a
  4  union
  5  select * from b
  6  where id in (2,3);

        ID
----------
         1
         2
         3

SQL> with a as (select * from t1),
  2  b as (select * from t2)
  3  select * from a
  4  union
  5  select * from b
  6  where id not in (2,3);

        ID
----------
         1
可以看出来where条件只是对每个SELECT语句的表做限制。


来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/24492954/viewspace-772056/,如需转载,请注明出处,否则将追究法律责任。

上一篇: 表空间用法
请登录后发表评论 登录
全部评论

注册时间:2011-04-09

  • 博文量
    41
  • 访问量
    239645