此頁沒有內容條目
內容

Shape Compute 命令

Shape COMPUTE 命令生成父 Recordset(其列由對子 Recordset 的引用組成)、可選的列(其內容是對子 Recordset 或以前成形的 Recordset 執(zhí)行合計函數(shù)的結果)和在可選的 BY 子句中開列出的任何子 Recordset 的列。

語法

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

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

[BY grp-field-list]"

組成說明

該命令的組成是:

child-command   如下之一。

?在尖括號(“{}”)中的查詢命令,返回 Recordset 對象。命令發(fā)布給基本數(shù)據(jù)提供者,其語法取決于該提供者的要求。雖然 ADO 并不要求使用任何指定的查詢語言,但通常是使用結構化查詢語言 (SQL)。

 

?以前成形的 Recordset 的名稱。

 

?另一個形狀(Shape)命令。

 

?TABLE 關鍵字,后跟表的名稱。

child-alias   別名,用于引用由 child-command 返回的 Recordset。在 COMPUTE 子句的列的列表中需要 child-alias,用于定義父和子 Recordset 對象的關系。

aggregate-command-field-list   列表,定義在生成的父中的列,含有對子 Recordset 執(zhí)行合計函數(shù)所產生的值。

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

對在 grp-field-list 中的每個列,在父和子 Recordset 對象中有對應的列。對父 Recordset 的每個行,grp-field-list 列有唯一的值,并且由父行引用的子 Recordset 由子行(其 grp-field-list 列含有與父行相同的值)單獨組成。

如果 COMPUTE 子句包含合計函數(shù),但沒有 BY 子句,那么,只有一個父行含有整個子 Recordset 的合計值。如果有 BY 子句,那么,有多個父行均分別含有引用和子 Recordset 的合計值。

操作

child-command 被發(fā)布給提供者,并返回子 Recordset。

COMPUTE 子句指定父 Recordset 的列,該 Recordset 可以是對子 Recordset 的引用、一個或多個合計、計算表達式或新列。如果有 BY 子句,那么,它定義的列同時被追加到父 Recordset 中。BY 子句指定子 Recordset 的行分組的方式。

例如,假定有一個人口統(tǒng)計表,包括 State、City 和 Population 字段(人口數(shù)字單獨說明)。

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

 

現(xiàn)在,發(fā)出該 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 分組,但不按照特定的順序。即分組將不采用字母或數(shù)字順序。

現(xiàn)在,您可以定位打開的父 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