select、where、from、to

select 语句返回一个记录数组(nid)。它可以与 wherefromto 子句组合使用。

示例:

下面的例子从 Customer 表中取出名字包含字母 "s" 的前 10 个名字:

(select Customer where 'First name' like "s" from 0 to 9).'first name'

where 子句

where 子句中的内容在服务器上执行。

  • 因此,在 where 子句中不能使用某些函数,例如 alertdialog

From To

使用 fromto 时,只会返回索引 0 到 9 之间的记录。

  • 这一特性适合取出前 x 条记录,或对查询结果分页。

执行块

执行块是 select 语句末尾句点之后的部分。在上面的例子中,执行块是 'first name'

更复杂的执行块可以包含变量,甚至再嵌入 select 语句。与函数一样,块中的最后一条语句决定结果数组的类型和值。

示例:

下面的代码生成一个数字数组,表示每位客户的销售总额:

(select Customer where 'First name' like "s" from 0 to 9).
  (
   var a := id;
   var i := select invoice where customer = a;
      sum(i.TOTAL);
   )

警告:

对于包含访问其他表的执行块,如果代码在服务器上执行,可能会出现异常。

  • 在这种情况下,最好改用 for i in select 循环。