DB2 9 应用开发(733 考试)认证指南,第 2 部分
2009-01-13 16:39:48 来源:WEB开发网WITH <COMMON NAME1> AS ( <SELECT EXPRESSION>), <COMMON NAME2>
AS (<SELECT EXPRESSION), & SELECT <COLUMN> FROM <TABLE_NAME> <WHERE_CLAUSE>
<table_name> 是数据库中的一个表,也可以是由一个包括 WITH 子句的 SQL 语句定义的 <Common name>。 下面是一个例子:
WITH PROD_QUANTITY AS
(SELECT PRODUCT_ID, SUM (QUANTITY) AS QUANTITY
FROM CUSTOMER_ORDER_ITEM
GROUP BY PRODUCT_ID),
TOTALS AS
(SELECT -1 AS PRODUCT_ID, SUM(QUANTITY) AS TOTAL)
SELECT PRODUCT_ID, QUANTITY
FROM PROD_QUANTITY
UNION
SELECT PRODUCT_ID, TOTALS
FROM TOTALS
ORDER BY 1 DESC
在上述例子中,prod_quantity 被定义为一个公共表表达式。它与一个名为 totals 的公共表表达式一起使用。最终的 SELECT 语句将从两个公共表表达式中进行选择。
下面看另一个例子:
WITH
PAYLEVEL AS
(SELECT EMPNO, EDLEVEL, YEAR(HIREDATE) AS HIREYEAR,
SALARY+BONUS+COMM AS TOTAL_PAY
FROM EMPLOYEE
WHERE EDLEVEL > 16),
PAYBYED (EDUC_LEVEL, YEAR_OF_HIRE, AVG_TOTAL_PAY) AS
(SELECT EDLEVEL, HIREYEAR, AVG(TOTAL_PAY)
FROM PAYLEVEL
GROUP BY EDLEVEL, HIREYEAR)
SELECT EMPNO, EDLEVEL, YEAR_OF_HIRE, TOTAL_PAY, DECIMAL(AVG_TOTAL_PAY,7,2)
FROM PAYLEVEL, PAYBYED
WHERE EDLEVEL = EDUC_LEVEL
AND HIREYEAR= YEAR_OF_HIRE
AND TOTAL_PAY < AVG_TOTAL_PAY
- ››db2 对float类型取char后显示科学计数法
- ››DB2中出现SQL1032N错误现象时的解决办法
- ››DB2 锁升级示例
- ››db2诊断系列之---定位锁等待问题
- ››db2 命令选项解释
- ››DB2 最佳实践: 使用 DB2 pureXML 管理 XML 数据的...
- ››DB2 9.5 SQL Procedure Developer 认证考试 735 准...
- ››DB2 9.5 SQL Procedure Developer 认证考试 735 准...
- ››DB2 9.5 SQL Procedure Developer 认证考试 735 准...
- ››DB2 基础: 表空间和缓冲池
- ››DB2 XML 编程,第 1 部分: 理解 XML 数据模型
- ››DB2 pureScale 实战
更多精彩
赞助商链接