ITPub博客

首页 > 数据库 > Oracle > with as的查询

with as的查询

原创 Oracle 作者:gtlions 时间:2008-10-15 11:21:02 0 删除 编辑

with as查询功能还是比较有用的,看下面的例子:

with t as
(select 'a' f1,1 f2,'aa' f3 from dual
union
select 'a' ,2 ,'bb' from dual
union
select 'a' ,3 ,'cc' from dual)
select distinct f1,max(f2) over(partition by f1 ) f2 ,max(f3) over(partition by f1 )f3 from t

这个例子是使用:

(select 'a' f1,1 f2,'aa' f3 from dual
union
select 'a' ,2 ,'bb' from dual
union
select 'a' ,3 ,'cc' from dual)

作为被查询的表格,后面紧跟着查询语句:

select distinct f1,max(f2) over(partition by f1 ) f2 ,max(f3) over(partition by f1 )f3 from t

这样的SQL可以在不使用临时表或者视图的时候快速的进行查询结果集再次查询。

[@more@]

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

请登录后发表评论 登录
全部评论

注册时间:2008-10-15

  • 博文量
    10
  • 访问量
    62431