Shape Compute 命令

Shape COMPUTE 命令生成父 Recordset(其列由对子 Recordset 的引用组成)、可选的列(其内容是对子 Recordset 或以前成形的 Recordset 执行合计函数的结果)和在可选的 BY 子句中开列出的任何子 Recordset 的列。

语法

"SHAPE {child-command} [AS] child-alias

COMPUTE child-alias [ ,aggregate-command-field-list]

[BY grp-field-list]"

组成说明

该命令的组成是:

child-command   如下之一。

child-alias   别名,用于引用由 child-command 返回的 Recordset。在 COMPUTE 子句的列的列表中需要 child-alias,用于定义父和子 Recordset 对象的关系。

aggregate-command-field-list   列表,定义在生成的父中的列,含有对子 Recordset 执行合计函数所产生的值。

grp-field-list   在父和子 Recordset 对象中的列的列表,指定在子中的行如何分组。

对在 grp-field-list 中的每个列,在父和子 Recordset 对象中有对应的列。对父 Recordset 的每个行,grp-field-list 列有唯一的值,并且由父行引用的子 Recordset 由子行(其 grp-field-list 列含有与父行相同的值)单独组成。

如果 COMPUTE 子句包含合计函数,但没有 BY 子句,那么,只有一个父行含有整个子 Recordset 的合计值。如果有 BY 子句,那么,有多个父行均分别含有引用和子 Recordset 的合计值。

操作

child-command 被发布给提供者,并返回子 Recordset

COMPUTE 子句指定父 Recordset 的列,该 Recordset 可以是对子 Recordset 的引用、一个或多个合计、计算表达式或新列。如果有 BY 子句,那么,它定义的列同时被追加到父 Recordset 中。BY 子句指定子 Recordset 的行分组的方式。

例如,假定有一个人口统计表,包括 State、City 和 Population 字段(人口数字单独说明)。

State City Population
WA Seattle 700,000
OR Medford 200,000
OR Portland 600,000
CA Los Angeles 900,000
CA San Diego 400,000
WA Tacoma 500,000
OR Corvallis 300,000

现在,发出该 Shape 命令:

   rst.Open      "SHAPE  {select * from demographics} AS rs
               COMPUTE SUM(rs.population), rs
               BY state", 
               connection

该命令打开具有两个层次的成形 Recordset。父层是生成的 Recordset,有合计列 (SUM(rs.population))、引用子 Recordset (rs) 的列和分组 Recordset (州)的列。子层是由查询命令 (select * from demographics) 返回的 Recordset

Recordset 具体行将由 State 分组,但不按照特定的顺序。即分组将不采用字母或数字顺序。

现在,您可以定位打开的父 Recordset,并访问具体的子 Recordset 对象。请参阅访问分级 Recordset 中的行

所得到的父和子具体的 Recordsets

SUM (rs.Population) rs State
1,300,000 Reference to child1 CA
1,200,000 Reference to child2 WA
1,100,000 Reference to child3 OR

子 1

State City Population
CA Los Angeles 900,000
CA San Diego 400,000

子 2

State City Population
WA Seattle 700,000
WA Tacoma 500,000

子 3

State City Population
OR Medford 200,000
OR Portland 600,000
OR Corvallis 300,000