📄 mdmscshapecomputecommand.htm
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML dir=ltr>
<HEAD>
<META HTTP-EQUIV="Content-Type" Content="text/html; charset=gb2312"><title>Shape Compute 命令</title>
<style>@import url(msdn_ie4.css);</style>
</HEAD>
<BODY>
<h2><a name="mdmscshapecomputecommand"></a>Shape Compute 命令</h2>
<p><a href="dir.htm">目录</a></p>
<p>
Shape COMPUTE 命令生成父 <b>Recordset</b>(其列由对子 <b>Recordset </b>的引用组成)、可选的列(其内容是对子 <b>Recordset</b> 或以前成形的 <b>Recordset</b> 执行合计函数的结果)和在可选的 BY 子句中开列出的任何子 <b>Recordset</b> 的列。</p>
<p class=label>
<b>语法</b></p>
<p>
"SHAPE <b>{</b><i>child-command</i><b>}</b> [AS] <i>child-alias</i></p>
<p>
COMPUTE <i>child-alias </i>[<i> ,aggregate-command-field-list</i>]</p>
<p>
[BY <i>grp-field-list</i>]"</p>
<p class=label>
<b>组成说明</b></p>
<p>
该命令的组成是:</p>
<p>
<i>child-command</i> 如下之一。
<ul type=disc>
<li>
在尖括号(“<b>{}</b>”)中的查询命令,返回 <b>Recordset</b> 对象。命令发布给基本数据提供者,其语法取决于该提供者的要求。虽然 ADO 并不要求使用任何指定的查询语言,但通常是使用结构化查询语言 (SQL)。<br><br></li>
<li>
以前成形的 <b>Recordset</b> 的名称。<br><br></li>
<li>
另一个形状(<b>Shape</b>)命令。<br><br></li>
<li>
TABLE 关键字,后跟表的名称。</li>
</ul>
<p>
<i>child-alias</i> 别名,用于引用由 <i>child-command </i>返回的 <b>Recordset</b>。在 COMPUTE 子句的列的列表中需要 <i>child-alias</i>,用于定义父和子 <b>Recordset</b> 对象的关系。</p>
<p>
<i>aggregate-command-field-list</i> 列表,定义在生成的父中的列,含有对子 <b>Recordset</b> 执行合计函数所产生的值。</p>
<p>
<i>grp-field-list</i> 在父和子 <b>Recordset</b> 对象中的列的列表,指定在子中的行如何分组。</p>
<p>
对在 <i>grp-field-list </i>中的每个列,在父和子 <b>Recordset </b>对象中有对应的列。对父 <b>Recordset </b>的每个行,<i>grp-field-list</i> 列有唯一的值,并且由父行引用的子 <b>Recordset</b> 由子行(其 <i>grp-field-list</i> 列含有与父行相同的值)单独组成。</p>
<p>
如果 <b>COMPUTE</b> 子句包含合计函数,但没有 <b>BY</b> 子句,那么,只有一个父行含有整个子 <b>Recordset</b> 的合计值。如果有 <b>BY</b> 子句,那么,有多个父行均分别含有引用和子 <b>Recordset</b> 的合计值。</p>
<p class=label>
<b>操作</b></p>
<p>
<i>child-command</i> 被发布给提供者,并返回子 <b>Recordset</b>。</p>
<p>
COMPUTE 子句指定父 <b>Recordset</b> 的列,该 <b>Recordset</b> 可以是对子 <b>Recordset</b> 的引用、一个或多个合计、计算表达式或新列。如果有 <b>BY</b> 子句,那么,它定义的列同时被追加到父 <b>Recordset</b> 中。<b>BY</b> 子句指定子 <b>Recordset</b> 的行分组的方式。</p>
<p>
例如,假定有一个人口统计表,包括 State、City 和 Population 字段(人口数字单独说明)。</p>
<table border=1 cellpadding=5 cols=3 frame=below rules=rows>
<tr valign=top>
<td class=label width=33%><b>State</b></td>
<td class=label width=33%><b>City</b></td>
<td class=label width=34%><b>Population</b></td>
</tr>
<tr valign=top>
<td width=33%>WA</td>
<td width=33%>Seattle</td>
<td width=34%>700,000</td>
</tr>
<tr valign=top>
<td width=33%>OR</td>
<td width=33%>Medford</td>
<td width=34%>200,000</td>
</tr>
<tr valign=top>
<td width=33%>OR</td>
<td width=33%>Portland</td>
<td width=34%>600,000</td>
</tr>
<tr valign=top>
<td width=33%>CA</td>
<td width=33%>Los Angeles</td>
<td width=34%>900,000</td>
</tr>
<tr valign=top>
<td width=33%>CA</td>
<td width=33%>San Diego</td>
<td width=34%>400,000</td>
</tr>
<tr valign=top>
<td width=33%>WA</td>
<td width=33%>Tacoma</td>
<td width=34%>500,000</td>
</tr>
<tr valign=top>
<td width=33%>OR</td>
<td width=33%>Corvallis</td>
<td width=34%>300,000</td>
</tr>
</table><br>
<p>
现在,发出该 Shape 命令:</p>
<pre> rst.Open "SHAPE {select * from demographics} AS rs
COMPUTE SUM(rs.population), rs
BY state",
connection
</pre>
<p>
该命令打开具有两个层次的成形 <b>Recordset</b>。父层是生成的 <b>Recordset</b>,有合计列 (SUM(rs.population))、引用子 <b>Recordset</b> (rs) 的列和分组 <b>Recordset</b> (州)的列。子层是由查询命令 (select * from demographics) 返回的 <b>Recordset</b>。</p>
<p>
子 <b>Recordset</b> 具体行将由 State 分组,但不按照特定的顺序。即分组将不采用字母或数字顺序。</p>
<p>
现在,您可以定位打开的父 <b>Recordset</b>,并访问具体的子 <b>Recordset</b> 对象。请参阅<a href="mdmscaccessingrowsinhierarchicalrecordset.htm">访问分级 Recordset 中的行</a>。</p>
<p class=label>
<b>所得到的父和子具体的 Recordsets</b></p>
<p class=label>
<b>父</b></p>
<table border=1 cellpadding=5 cols=3 frame=below rules=rows>
<tr valign=top>
<td class=label width=33%><b>SUM (rs.Population)</b></td>
<td class=label width=33%><b>rs</b></td>
<td class=label width=34%><b>State</b></td>
</tr>
<tr valign=top>
<td width=33%>1,300,000</td>
<td width=33%>Reference to child1</td>
<td width=34%>CA</td>
</tr>
<tr valign=top>
<td width=33%>1,200,000</td>
<td width=33%>Reference to child2</td>
<td width=34%>WA</td>
</tr>
<tr valign=top>
<td width=33%>1,100,000</td>
<td width=33%>Reference to child3</td>
<td width=34%>OR</td>
</tr>
</table><br>
<p class=label>
<b>子 1</b></p>
<table border=1 cellpadding=5 cols=3 frame=below rules=rows>
<tr valign=top>
<td class=label width=33%><b>State</b></td>
<td class=label width=33%><b>City</b></td>
<td class=label width=34%><b>Population</b></td>
</tr>
<tr valign=top>
<td width=33%>CA</td>
<td width=33%>Los Angeles</td>
<td width=34%>900,000</td>
</tr>
<tr valign=top>
<td width=33%>CA</td>
<td width=33%>San Diego</td>
<td width=34%>400,000</td>
</tr>
</table><br>
<p class=label>
<b>子 2</b></p>
<table border=1 cellpadding=5 cols=3 frame=below rules=rows>
<tr valign=top>
<td class=label width=33%><b>State</b></td>
<td class=label width=33%><b>City</b></td>
<td class=label width=34%><b>Population</b></td>
</tr>
<tr valign=top>
<td width=33%>WA</td>
<td width=33%>Seattle</td>
<td width=34%>700,000</td>
</tr>
<tr valign=top>
<td width=33%>WA</td>
<td width=33%>Tacoma</td>
<td width=34%>500,000</td>
</tr>
</table><br>
<p class=label>
<b>子 3</b></p>
<table border=1 cellpadding=5 cols=3 frame=below rules=rows>
<tr valign=top>
<td class=label width=33%><b>State</b></td>
<td class=label width=33%><b>City</b></td>
<td class=label width=34%><b>Population</b></td>
</tr>
<tr valign=top>
<td width=33%>OR</td>
<td width=33%>Medford</td>
<td width=34%>200,000</td>
</tr>
<tr valign=top>
<td width=33%>OR</td>
<td width=33%>Portland</td>
<td width=34%>600,000</td>
</tr>
<tr valign=top>
<td width=33%>OR</td>
<td width=33%>Corvallis</td>
<td width=34%>300,000</td>
</tr>
</table><br>
<center> <A HREF="http://www.51windows.Net">www.51windows.Net</A></center>
<SCRIPT LANGUAGE="JavaScript" src="/log/sitelog2.asp"></SCRIPT>
<script src="script.js"></script></BODY>
</HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -