数据库函数

本节介绍用于管理数据(一行数据为一个记录)的函数。

批注图标 Database 类可能会与集成在 LibreOffice 中的数据库混淆。然而,在 LibreOffice 中数据库与在 LibreOffice Calc 中的 Database 类没有联系。

示例数据:

某些函数功能说明示例中将用到以下数据:

A1:E10 区域列出了应邀参加 Joe 生日晚会的孩子们。给出了每个孩子的以下信息:A 栏列出名字,B 栏列出年级,接着是年龄、到学校的距离 (以米为单位)、每个人的体重 (以千克为单位)。

A

B

C

D

E

1

姓名

年级

年龄

到学校的距离

体重

2

Andy

3

9

150

40

3

Betty

4

10

1000

42

4

Charles

3

10

300

51

5

Daniel

5

11

1200

48

6

Eva

2

8

650

33

7

Frank

2

7

300

42

8

Greta

1

7

200

36

9

Harry

3

9

1200

44

10

Irene

2

8

1000

42

11

12

13

姓名

年级

年龄

到学校的距离

体重

14

>600

15

16

DCOUNT

5


单元格 B16 中的公式为 =DCOUNT(A1:E10, D1, A13:E14)

数据库函数参数:

以下各项是所有数据库函数的参数定义:

database是用来定义该数据库的单元格区域。

DatabaseField specifies the column where the function operates on after the search criteria of the first parameter is applied and the data rows are selected. It is not related to the search criteria itself. For the DatabaseField parameter you can enter a reference to a header cell or a number to specify the column within the Database area, starting with 1. To reference a column by means of the literal column header name, place quotation marks around the header name.

SearchCriteria 是指含有查找条件的单元格区域。如果您在同一行中键入了数个查找条件,就会采用 AND 来连接它们。如果您在不同的行中键入了数个查找条件,就会采用 OR 来连接它们。查找条件区域内的空白单元格将被忽略。

选择 - LibreOffice Calc - 计算以定义查找同等条目时 LibreOffice Calc 如何操作。

请参见关于 条件统计与求和 的 Wiki 页面。

DAVERAGE

DAVERAGER 返回所有行(数据库记录)中符合指定搜索条件的所有单元格(字段)的平均值。

查找支持正则表达式。例如,您可以输入 "all.*" 来查找起始部分为 "all" 且后跟任意字符的内容首次出现的位置。如果您想要查找一个同时也是正则表达式的文本,则您必须在每个字符前面加上一个 \ 字符。您能够在 - LibreOffice Calc - 计算中切换正则表达式自动求值功能的打开和关闭状态。

语法

DAVERAGE(Database; DatabaseField; SearchCriteria)

For the DatabaseField parameter you can enter a reference to a header cell or a number to specify the column within the Database area, starting with 1. To reference a column by means of the literal column header name, place quotation marks around the header name.

示例

要计算上例中所有同龄孩子的平均体重(请向上滚动),请在单元格 B16 中输入以下公式:

=DAVERAGE(A1:E10;"体重";A13:E14)

在“年龄”下的第 14 行处依次输入 7, 8, 9, 等等。将显示每个年龄组中所有孩子的平均体重。

DCOUNT

DCOUNT 计算数据库中符合指定条件并且DatabaseField字段中包含数值型值的记录数。

查找支持正则表达式。例如,您可以输入 "all.*" 来查找起始部分为 "all" 且后跟任意字符的内容首次出现的位置。如果您想要查找一个同时也是正则表达式的文本,则您必须在每个字符前面加上一个 \ 字符。您能够在 - LibreOffice Calc - 计算中切换正则表达式自动求值功能的打开和关闭状态。

语法

DCOUNT(Database, [DatabaseField], SearchCriteria)

如果 DatabaseField 参数被忽略,那么DCOUNT 返回所有满足条件 Criteria 的记录数。 For the DatabaseField parameter you can enter a reference to a header cell or a number to specify the column within the Database area, starting with 1. To reference a column by means of the literal column header name, place quotation marks around the header name.

示例

在上面的示例中(请向上滚动),我们要计算的是上学路程超过 600 米的孩子的数目。计算结果存储在单元格 B16 中。请将光标置于单元格 B16 中,然后在 B16 中输入公式 =DCOUNT(A1:E10;0;A13:E14)函数向导可帮助您输入值。

Database 是要计算的数据区域,包括其标题:在本例中为 A1:E10。DatabaseField 指定用于查找条件的列:在本例中是整个数据库。SearchCriteria 是您可以输入查找参数的范围:在本例中为 A13:E14。

要了解二年级有多少孩子的年龄超过 7 岁,请删除单元格 D14 中的内容 >600,然后在“年级”下的单元格 B14 中输入 2,并在右边的单元格 C14 中输入 >7。结果等于 2,有两个二年级孩子的年龄超过 7 岁。由于同一行中有两个查找条件,所以会用 AND 来连接这两个条件。

DCOUNTA

DCOUNTA 计算数据库中匹配指定查找条件并包含数字或字母数字值的行(记录)数。

查找支持正则表达式。例如,您可以输入 "all.*" 来查找起始部分为 "all" 且后跟任意字符的内容首次出现的位置。如果您想要查找一个同时也是正则表达式的文本,则您必须在每个字符前面加上一个 \ 字符。您能够在 - LibreOffice Calc - 计算中切换正则表达式自动求值功能的打开和关闭状态。

语法

DCOUNTA(Database; DatabaseField; SearchCriteria)

If the DatabaseField argument is omitted, DCOUNTA returns the count of all records that satisfy Criteria. For the DatabaseField parameter you can enter a reference to a header cell or a number to specify the column within the Database area, starting with 1. To reference a column by means of the literal column header name, place quotation marks around the header name.

示例

在上面的示例中(请向上滚动),您可以查找以字母 E 或字母表中 E 后面的字母作为名字的首字母的孩子的数目。在 B16 中编辑公式 =DCOUNTA(A1:E10;"Age";A13:E14)。删除旧的查找条件,在“名字”下的单元格 A14 中输入 >=E。计算结果是 5。如果您现在删除第 8 行中有关 Greta 的所有数据,那么计算结果就变为 4,因为第 8 行中已经不含有任何数值,所以计算时没有包括它。名字 Greta 是文字,不是数值。请注意,数据库字段的参数必须指向含有数值的列。

DGET

DGET 返回数据库中符合指定查找条件的引用单元格的内容。如果出错,函数将返回 #VALUE!,表示找不到行,或返回 Err502,表示找到多个单元格。

查找支持正则表达式。例如,您可以输入 "all.*" 来查找起始部分为 "all" 且后跟任意字符的内容首次出现的位置。如果您想要查找一个同时也是正则表达式的文本,则您必须在每个字符前面加上一个 \ 字符。您能够在 - LibreOffice Calc - 计算中切换正则表达式自动求值功能的打开和关闭状态。

语法

DGET(Database; DatabaseField; SearchCriteria)

For the DatabaseField parameter you can enter a reference to a header cell or a number to specify the column within the Database area, starting with 1. To reference a column by means of the literal column header name, place quotation marks around the header name.

示例

在上例中(请向上滚动),我们要确定名字输入在单元格 A14 中的孩子所在的年级。在单元格 B16 中输入了公式,此公式与以前的示例略有不同,因为只有一列(一个数据库字段)可以作为 DatabaseField 的输入。输入以下公式:

=DGET(A1:E10;"年级";A13:E14)

在单元格 A14 中输入 Frank,返回结果 2。Frank 上二年级。输入 "年龄" 代替 "年级",就可以获得 Frank 的年龄。

或者仅在单元格 C14 中输入数值 11,并删除这行中的其他数据。按照以下所示编辑 B16 中的公式:

=DGET(A1:E10;"名字";A13:E14)

现在您要确定的是符合某一年龄的孩子的名字。这样您获得的结果便是:Daniel。也就是说年龄为 11 岁的孩子名字是 Daniel。

DMAX

DMAX 返回数据库(所有记录)中符合指定查找条件的最大单元格(字段)内容。

查找支持正则表达式。例如,您可以输入 "all.*" 来查找起始部分为 "all" 且后跟任意字符的内容首次出现的位置。如果您想要查找一个同时也是正则表达式的文本,则您必须在每个字符前面加上一个 \ 字符。您能够在 - LibreOffice Calc - 计算中切换正则表达式自动求值功能的打开和关闭状态。

语法

DMAX(Database; DatabaseField; SearchCriteria)

For the DatabaseField parameter you can enter a reference to a header cell or a number to specify the column within the Database area, starting with 1. To reference a column by means of the literal column header name, place quotation marks around the header name.

示例

要计算上例中每个年级最重的孩子的体重(请向上滚动),请在单元格 B16 中输入以下公式:

=DMAX(A1:E10;"体重";A13:E14)

在“年级”下依次输入 1, 2, 3, 等等。输入年级后,将显示该年级中最重的孩子的体重。

DMIN

DMIN 返回数据库中匹配指定查找条件的最小单元格(字段)的内容。

查找支持正则表达式。例如,您可以输入 "all.*" 来查找起始部分为 "all" 且后跟任意字符的内容首次出现的位置。如果您想要查找一个同时也是正则表达式的文本,则您必须在每个字符前面加上一个 \ 字符。您能够在 - LibreOffice Calc - 计算中切换正则表达式自动求值功能的打开和关闭状态。

语法

DMIN(Database; DatabaseField; SearchCriteria)

For the DatabaseField parameter you can enter a reference to a header cell or a number to specify the column within the Database area, starting with 1. To reference a column by means of the literal column header name, place quotation marks around the header name.

示例

要计算上例中各年级孩子距学校最近的距离(请向上滚动),请在单元格 B16 中输入以下公式:

=DMIN(A1:E10;"上学路程";A13:E14)

在“年级”下的第 14 行处依次输入 1, 2, 3, 等等。将显示每个年级到学校的最短路程。

DPRODUCT

DPRODUCT 将单元格内容符合查找条件的数据区域的所有单元格相乘。

查找支持正则表达式。例如,您可以输入 "all.*" 来查找起始部分为 "all" 且后跟任意字符的内容首次出现的位置。如果您想要查找一个同时也是正则表达式的文本,则您必须在每个字符前面加上一个 \ 字符。您能够在 - LibreOffice Calc - 计算中切换正则表达式自动求值功能的打开和关闭状态。

语法

DPRODUCT(Database; DatabaseField; SearchCriteria)

For the DatabaseField parameter you can enter a reference to a header cell or a number to specify the column within the Database area, starting with 1. To reference a column by means of the literal column header name, place quotation marks around the header name.

示例

对于上面的生日晚会示例(请向上滚动),此函数不适用。

DSTDEV

DSTDEV 通过使用数据库列中符合给定条件的数据,来计算基于抽样人群的标准偏差。记录被视为一个数据抽样。这表示示例中的孩子代表所有孩子中的一种典型情况。值得注意的是,如果抽样的数据少于一千个,则无法获得具有代表性的结果。

查找支持正则表达式。例如,您可以输入 "all.*" 来查找起始部分为 "all" 且后跟任意字符的内容首次出现的位置。如果您想要查找一个同时也是正则表达式的文本,则您必须在每个字符前面加上一个 \ 字符。您能够在 - LibreOffice Calc - 计算中切换正则表达式自动求值功能的打开和关闭状态。

语法

DSTDEV(Database; DatabaseField; SearchCriteria)

For the DatabaseField parameter you can enter a reference to a header cell or a number to specify the column within the Database area, starting with 1. To reference a column by means of the literal column header name, place quotation marks around the header name.

示例

要计算示例中所有同龄孩子体重的标准偏差(请向上滚动),请在单元格 B16 中输入以下公式:

=DSTDEV(A1:E10;"体重";A13:E14)

在“年龄”下的第 14 行处依次输入 7, 8, 9,等等。结果显示的是每个年龄组中所有孩子体重的标准偏差。

DSTDEVP

DSTDEVP 计算基于数据区域中匹配查找条件的所有单元格的总体样本的标准偏差。示例中的记录被视为一个完整的总体样本。

查找支持正则表达式。例如,您可以输入 "all.*" 来查找起始部分为 "all" 且后跟任意字符的内容首次出现的位置。如果您想要查找一个同时也是正则表达式的文本,则您必须在每个字符前面加上一个 \ 字符。您能够在 - LibreOffice Calc - 计算中切换正则表达式自动求值功能的打开和关闭状态。

语法

DSTDEVP(Database; DatabaseField; SearchCriteria)

For the DatabaseField parameter you can enter a reference to a header cell or a number to specify the column within the Database area, starting with 1. To reference a column by means of the literal column header name, place quotation marks around the header name.

示例

要计算参加 Joe 生日晚会的所有同龄孩子体重的标准偏差(请向上滚动),请在单元格 B16 中输入以下公式:

=DSTDEVP(A1:E10;"体重";A13:E14)

在“年龄”下的第 14 行中依次输入 7, 8, 9, 等等。计算结果是所有已检查体重的同年龄孩子体重的标准偏差。

DSUM

DSUM 计算的是所有行(记录)中的数据库字段中,符合指定搜索条件的所有单元格数据的总和。

查找支持正则表达式。例如,您可以输入 "all.*" 来查找起始部分为 "all" 且后跟任意字符的内容首次出现的位置。如果您想要查找一个同时也是正则表达式的文本,则您必须在每个字符前面加上一个 \ 字符。您能够在 - LibreOffice Calc - 计算中切换正则表达式自动求值功能的打开和关闭状态。

语法

DSUM(Database; DatabaseField; SearchCriteria)

For the DatabaseField parameter you can enter a reference to a header cell or a number to specify the column within the Database area, starting with 1. To reference a column by means of the literal column header name, place quotation marks around the header name.

示例

要计算参加 Joe 生日晚会的所有二年级孩子上学路程的总和(请向上滚动),请在单元格 B16 中输入以下公式:

=DSUM(A1:E10;"上学路程";A13:E14)

在“年级”下的第 14 行处输入数字 2。将显示二年级的所有孩子上学路程的总和 (1950)。

DVAR

DVAR 返回匹配指定查找条件的所有记录的数据库字段中所有单元格数据的方差。示例中的记录被视为一个数据抽样。如果抽样总体样本少于一千个,则无法获得具有代表性的结果。

查找支持正则表达式。例如,您可以输入 "all.*" 来查找起始部分为 "all" 且后跟任意字符的内容首次出现的位置。如果您想要查找一个同时也是正则表达式的文本,则您必须在每个字符前面加上一个 \ 字符。您能够在 - LibreOffice Calc - 计算中切换正则表达式自动求值功能的打开和关闭状态。

语法

DVAR(Database; DatabaseField; SearchCriteria)

For the DatabaseField parameter you can enter a reference to a header cell or a number to specify the column within the Database area, starting with 1. To reference a column by means of the literal column header name, place quotation marks around the header name.

示例

要计算上例中所有同龄孩子体重的方差(请向上滚动),请在单元格 B16 中输入以下公式:

=DVAR(A1:E10;"体重";A13:E14)

在“年龄”下的第 14 行处依次输入 7, 8, 9, 等等。您将看到该年龄组中所有孩子体重的方差。

DVARP

DVARP 计算所有匹配查找条件的记录的数据库字段中所有单元格值的方差。示例中的记录视为一个总体样本。

查找支持正则表达式。例如,您可以输入 "all.*" 来查找起始部分为 "all" 且后跟任意字符的内容首次出现的位置。如果您想要查找一个同时也是正则表达式的文本,则您必须在每个字符前面加上一个 \ 字符。您能够在 - LibreOffice Calc - 计算中切换正则表达式自动求值功能的打开和关闭状态。

语法

DVARP(Database; DatabaseField; SearchCriteria)

For the DatabaseField parameter you can enter a reference to a header cell or a number to specify the column within the Database area, starting with 1. To reference a column by means of the literal column header name, place quotation marks around the header name.

示例

要计算参加 Joe 生日晚会的所有同年龄孩子体重的方差(请向上滚动),请在单元格 B16 中输入以下公式:

=DVARP(A1:E10;"体重";A13:E14)

在“年龄”下的第 14 行中依次输入 7, 8, 9, 等等。将显示参加 Joe 生日晚会的所有同年龄孩子体重的方差。