Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3922273
  • 博文数量: 534
  • 博客积分: 10470
  • 博客等级: 上将
  • 技术积分: 4800
  • 用 户 组: 普通用户
  • 注册时间: 2006-05-26 14:08
文章分类

全部博文(534)

文章存档

2024年(1)

2021年(1)

2019年(1)

2017年(1)

2016年(2)

2013年(2)

2012年(10)

2011年(43)

2010年(10)

2009年(17)

2008年(121)

2007年(252)

2006年(73)

分类: Oracle

2008-06-28 09:01:06

SQL> @select_with.sql

DNAME DEPT_TOTAL
-------------- ----------

RESEARCH 10875

SQL> l
  1 WITH
  2 dept_cost AS
  3 (
  4 SELECT d.dname, SUM(e.sal) dept_total
  5 FROM emp e, dept d
  6 WHERE e.deptno = d.deptno
  7 GROUP BY d.dname
  8 ),
  9 avg_cost AS
 10 (
 11 SELECT SUM(dept_total)/COUNT(*) avg
 12 FROM dept_cost
 13 )
 14 SELECT dname, dept_total FROM dept_cost
 15 WHERE dept_total > (SELECT avg FROM avg_cost)
 16* ORDER BY dname


Subquery Factoring: Example The following statement creates the query names dept_costs and avg_cost for the initial query block containing a join, and then uses the query names in the body of the main query.

Learn MOre:
阅读(2428) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~