データベース関数

ここでは、データベース (1 行のデータを 1 つのレコードと見なす) のデータを処理する関数について説明します。

note

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;0;A13:E14) です。

データベース関数のパラメーター:

次に示す項目は、全データベース関数のパラメーター定義です。

Database is the cell range defining the database. The first row of the range contains the field names, and following rows are records with corresponding field values.

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 (from the first row of Database range), place quotation marks around the header name.

SearchCriteria is the cell range containing search criteria. Like Database, its first row is also field names, and following rows are conditions for related fields. If you write several criteria in one row they are connected by AND. If you write the criteria in different rows they are connected by OR. Empty cells in the search criteria range will be ignored.

Choose - LibreOffice Calc - Calculate to define how LibreOffice Calc acts when searching for identical entries.

See also the Wiki page about Conditional Counting and Summation.

DAVERAGE

DAVERAGE は、データベース内で、検索条件を満たすすべての行 (データベースレコード) のすべてのセル (フィールド) の内容の平均値を返します。

The search supports wildcards or regular expressions. With regular expressions enabled, you can enter "all.*", for example to find the first location of "all" followed by any characters. If you want to search for a text that is also a regular expression, you must either precede every character with a "\" character, or enclose the text into \Q...\E. You can switch the automatic evaluation of wildcards or regular expression on and off in - LibreOffice Calc - Calculate.

warning

When using functions where one or more arguments are search criteria strings that represents a regular expression, the first attempt is to convert the string criteria to numbers. For example, ".0" will convert to 0.0 and so on. If successful, the match will not be a regular expression match but a numeric match. However, when switching to a locale where the decimal separator is not the dot makes the regular expression conversion work. To force the evaluation of the regular expression instead of a numeric expression, use some expression that can not be misread as numeric, such as ".[0]" or ".\0" or "(?i).0".


Syntax

DAVERAGE(データベース; データベースフィールド; 検索条件)

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 (from the first row of Database range), place quotation marks around the header name.

Example

年齢が同じ子供たち全員の平均体重を知るには (上にスクロールしてください)、次の数式をセル B16 に入力します。

=DAVERAGE(A1:E10;"Weight";A13:E14)

行 14 の Age には、7、8、9 などを順に入力します。年齢が同じ子供たち全員の平均体重が表示されます。

DCOUNTA

DCOUNTA は、検索条件に一致する数値またはアルファベット値を含むデータベース内の行 (レコード) 数を返します。

The search supports wildcards or regular expressions. With regular expressions enabled, you can enter "all.*", for example to find the first location of "all" followed by any characters. If you want to search for a text that is also a regular expression, you must either precede every character with a "\" character, or enclose the text into \Q...\E. You can switch the automatic evaluation of wildcards or regular expression on and off in - LibreOffice Calc - Calculate.

warning

When using functions where one or more arguments are search criteria strings that represents a regular expression, the first attempt is to convert the string criteria to numbers. For example, ".0" will convert to 0.0 and so on. If successful, the match will not be a regular expression match but a numeric match. However, when switching to a locale where the decimal separator is not the dot makes the regular expression conversion work. To force the evaluation of the regular expression instead of a numeric expression, use some expression that can not be misread as numeric, such as ".[0]" or ".\0" or "(?i).0".


Syntax

DCOUNTA(データベース; データベースフィールド; 検索条件)

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 (from the first row of Database range), place quotation marks around the header name.

If you choose to omit the DatabaseField argument, your formula should be of the form =DCOUNTA(Database; ; SearchCriteria).

Example

上記の例 (上にスクロールしてください) では、名前が E 以降の文字で始まる子供の数を検索します。B16 の数式を =DCOUNTA(A1:E10;"Name";A13:E14) に編集します。古い検索条件を削除し、フィールド A14 の Name の下に >=E を入力します。結果は 5 です。行 8 の Greta のすべての数値を削除すると、結果は 4 に変わります。行 8 は値を何も含んでいないので、カウントされなくなります。名前 Greta はテキストで、値ではありません。データベースフィールドパラメーターは、値を含むことができる列を指す必要があります。

DCOUNT

DCOUNTは、検索条件に一致する数値を含むデータベース内の行 (レコード) 数を返します。

The search supports wildcards or regular expressions. With regular expressions enabled, you can enter "all.*", for example to find the first location of "all" followed by any characters. If you want to search for a text that is also a regular expression, you must either precede every character with a "\" character, or enclose the text into \Q...\E. You can switch the automatic evaluation of wildcards or regular expression on and off in - LibreOffice Calc - Calculate.

warning

When using functions where one or more arguments are search criteria strings that represents a regular expression, the first attempt is to convert the string criteria to numbers. For example, ".0" will convert to 0.0 and so on. If successful, the match will not be a regular expression match but a numeric match. However, when switching to a locale where the decimal separator is not the dot makes the regular expression conversion work. To force the evaluation of the regular expression instead of a numeric expression, use some expression that can not be misread as numeric, such as ".[0]" or ".\0" or "(?i).0".


Syntax

DCOUNT(データベース; データベースフィールド; 検索条件)

If the DatabaseField argument is omitted, DCOUNT 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 (from the first row of Database range), place quotation marks around the header name.

If you choose to omit the DatabaseField argument, your formula should be of the form =DCOUNT(Database; ; SearchCriteria).

Example

上記の例 (上にスクロールしてください) では、学校までの距離が 600 メートルを超える子供の数を調べます。この結果は、セル B16 に格納されます。セル B16 にカーソルを置きます。B16 に数式 =DCOUNT(A1:E10;0;A13:E14) を入力します。範囲の入力には、関数ウィザード が役立ちます。

データベース は、ヘッダーを含む評価対象のデータ範囲です。この場合は、A1:E10 です。データベースフィールド は、検索条件の列を指定します。この場合は、データベース全体です。検索条件 は、検索パラメーターを入力できる範囲です。この場合は、A13:E14 です。

2 年生で 7 歳を過ぎている子供の数を知るには、セル D14 の入力 >600 を削除し、Grade のセル B14 に 2 を入力し、右のセル C14 に >7 を入力します。結果は 2 です。2 人の子供が 2 年生で 7 歳を過ぎています。両方の条件は同じ行内にあるので、AND によって結合されます。

DGET

DGET は、検索条件に一致する、データベース内の 1 つのセルの内容を返します。セルが見つからない場合は #VALUE! を、2 つ以上のセルが見つかると エラー: 502 を返します。

The search supports wildcards or regular expressions. With regular expressions enabled, you can enter "all.*", for example to find the first location of "all" followed by any characters. If you want to search for a text that is also a regular expression, you must either precede every character with a "\" character, or enclose the text into \Q...\E. You can switch the automatic evaluation of wildcards or regular expression on and off in - LibreOffice Calc - Calculate.

warning

When using functions where one or more arguments are search criteria strings that represents a regular expression, the first attempt is to convert the string criteria to numbers. For example, ".0" will convert to 0.0 and so on. If successful, the match will not be a regular expression match but a numeric match. However, when switching to a locale where the decimal separator is not the dot makes the regular expression conversion work. To force the evaluation of the regular expression instead of a numeric expression, use some expression that can not be misread as numeric, such as ".[0]" or ".\0" or "(?i).0".


Syntax

DGET(データベース; データベースフィールド; 検索条件)

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 (from the first row of Database range), place quotation marks around the header name.

Example

上記の例 (上にスクロールしてください) では、セル A14 に入力した名前の子供がどの学年にいるかを調べます。データベースフィールド には 1 列 (1 つのデータベースフィールド) しか入力できないので、数式はセル B16 に入力され、前の例とは少し異なります。次の数式を入力します:

=DGET(A1:E10;"Grade";A13:E14)

A14 に名前 Frank を入力すると、結果 2 が表示されます。Frank は 2 年生です。"Grade" の代わりに "Age" を入力すると、Frank の年齢が表示されます。

または、セル C14 だけに値 11 を入力して、この行のほかの入力を削除します。B16 の数式を次のように編集します:

=DGET(A1:E10;"Name";A13:E14)

学年のかわりに名前が検査されます。11歳の子供は Daniel 1人です。

DMAX

DMAX は、検索条件を満たすデータベース内のすべての行 (レコード) の中からセル (フィールド) の最大値を返します。

The search supports wildcards or regular expressions. With regular expressions enabled, you can enter "all.*", for example to find the first location of "all" followed by any characters. If you want to search for a text that is also a regular expression, you must either precede every character with a "\" character, or enclose the text into \Q...\E. You can switch the automatic evaluation of wildcards or regular expression on and off in - LibreOffice Calc - Calculate.

warning

When using functions where one or more arguments are search criteria strings that represents a regular expression, the first attempt is to convert the string criteria to numbers. For example, ".0" will convert to 0.0 and so on. If successful, the match will not be a regular expression match but a numeric match. However, when switching to a locale where the decimal separator is not the dot makes the regular expression conversion work. To force the evaluation of the regular expression instead of a numeric expression, use some expression that can not be misread as numeric, such as ".[0]" or ".\0" or "(?i).0".


Syntax

DMAX(データベース; データベースフィールド; 検索条件)

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 (from the first row of Database range), place quotation marks around the header name.

Example

各学年で最も重い子供の体重を知るには (上にスクロールしてください)、次の数式をセル B16 に入力します。

=DMAX(A1:E10;"Weight";A13:E14)

Grade には、1、2、3 などを順に入力します。学年番号を入力すると、その学年でもっとも重い子供の体重が表示されます。

DMIN

DMIN は、データベースにおいて検索基準を満たす行のうち、データベースフィールドの最小値を返します。

The search supports wildcards or regular expressions. With regular expressions enabled, you can enter "all.*", for example to find the first location of "all" followed by any characters. If you want to search for a text that is also a regular expression, you must either precede every character with a "\" character, or enclose the text into \Q...\E. You can switch the automatic evaluation of wildcards or regular expression on and off in - LibreOffice Calc - Calculate.

warning

When using functions where one or more arguments are search criteria strings that represents a regular expression, the first attempt is to convert the string criteria to numbers. For example, ".0" will convert to 0.0 and so on. If successful, the match will not be a regular expression match but a numeric match. However, when switching to a locale where the decimal separator is not the dot makes the regular expression conversion work. To force the evaluation of the regular expression instead of a numeric expression, use some expression that can not be misread as numeric, such as ".[0]" or ".\0" or "(?i).0".


Syntax

DMIN(データベース; データベースフィールド; 検索条件)

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 (from the first row of Database range), place quotation marks around the header name.

Example

各学年で通学路が最も短い子供を知るには (上にスクロールしてください)、次の数式をセル B16 に入力します。

=DMIN(A1:E10;"Distance to School";A13:E14)

行 14 の Grade には、1、2、3 などを順に入力します。各学年の学校への最短距離が表示されます。

DPRODUCT

DPRODUCT は、セルの内容が検索条件を満たすデータ範囲の、すべてのセルの積を返します。

The search supports wildcards or regular expressions. With regular expressions enabled, you can enter "all.*", for example to find the first location of "all" followed by any characters. If you want to search for a text that is also a regular expression, you must either precede every character with a "\" character, or enclose the text into \Q...\E. You can switch the automatic evaluation of wildcards or regular expression on and off in - LibreOffice Calc - Calculate.

warning

When using functions where one or more arguments are search criteria strings that represents a regular expression, the first attempt is to convert the string criteria to numbers. For example, ".0" will convert to 0.0 and so on. If successful, the match will not be a regular expression match but a numeric match. However, when switching to a locale where the decimal separator is not the dot makes the regular expression conversion work. To force the evaluation of the regular expression instead of a numeric expression, use some expression that can not be misread as numeric, such as ".[0]" or ".\0" or "(?i).0".


Syntax

DPRODUCT(データベース; データベースフィールド; 検索条件)

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 (from the first row of Database range), place quotation marks around the header name.

Example

上記誕生日パーティの例では (上にスクロールしてください)、この関数は有効に使用できません。

DSTDEV

DSTDEV は、データベースにおいて検索基準を満たす行のうち、データベースフィールドの値の標本をとって、母集団の標準偏差を計算します。つまり、DSTDEV はレコードをデータの標本として扱います。つまり、上記例の子供はすべての子供の典型です。ただし、1000 人に満たない標本だけでは本当の典型にはなり得ません。

The search supports wildcards or regular expressions. With regular expressions enabled, you can enter "all.*", for example to find the first location of "all" followed by any characters. If you want to search for a text that is also a regular expression, you must either precede every character with a "\" character, or enclose the text into \Q...\E. You can switch the automatic evaluation of wildcards or regular expression on and off in - LibreOffice Calc - Calculate.

warning

When using functions where one or more arguments are search criteria strings that represents a regular expression, the first attempt is to convert the string criteria to numbers. For example, ".0" will convert to 0.0 and so on. If successful, the match will not be a regular expression match but a numeric match. However, when switching to a locale where the decimal separator is not the dot makes the regular expression conversion work. To force the evaluation of the regular expression instead of a numeric expression, use some expression that can not be misread as numeric, such as ".[0]" or ".\0" or "(?i).0".


Syntax

DSTDEV(データベース; データベースフィールド; 検索条件)

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 (from the first row of Database range), place quotation marks around the header name.

Example

年齢が同じ子供たち全員の体重の標準偏差を求めるには (上にスクロールしてください)、次の数式をセル B16 に入力します。

=DSTDEV(A1:E10;"Weight";A13:E14)

行 14 の Age には、7、8、9 などを順に入力します。表示される結果は、この年齢の子供たち全員の体重の標準偏差です。

DSTDEVP

DSTDEVP は、検索基準を満たすデータ範囲内のすべてのセルに基づいて、母集団の標準偏差を計算します。つまり、DSTDEVP はレコードを母集団全体として扱います。

The search supports wildcards or regular expressions. With regular expressions enabled, you can enter "all.*", for example to find the first location of "all" followed by any characters. If you want to search for a text that is also a regular expression, you must either precede every character with a "\" character, or enclose the text into \Q...\E. You can switch the automatic evaluation of wildcards or regular expression on and off in - LibreOffice Calc - Calculate.

warning

When using functions where one or more arguments are search criteria strings that represents a regular expression, the first attempt is to convert the string criteria to numbers. For example, ".0" will convert to 0.0 and so on. If successful, the match will not be a regular expression match but a numeric match. However, when switching to a locale where the decimal separator is not the dot makes the regular expression conversion work. To force the evaluation of the regular expression instead of a numeric expression, use some expression that can not be misread as numeric, such as ".[0]" or ".\0" or "(?i).0".


Syntax

DSTDEVP(データベース; データベースフィールド; 検索条件)

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 (from the first row of Database range), place quotation marks around the header name.

Example

ジョーの誕生パーティに参加した、年齢が同じ子供たち全員の体重の標準偏差を求めるには (上にスクロールしてください)、次の数式をセル B16 に入力します。

=DSTDEVP(A1:E10;"Weight";A13:E14)

行 14 の Age には、7、8、9 などを順に入力します。結果は、体重を検査された同年齢の子供たち全員の体重の標準偏差です。

DSUM

DSUM は、入力された検索条件を満たすすべての行 (レコード) のデータベースフィールドの、すべてのセルの合計を返します。

The search supports wildcards or regular expressions. With regular expressions enabled, you can enter "all.*", for example to find the first location of "all" followed by any characters. If you want to search for a text that is also a regular expression, you must either precede every character with a "\" character, or enclose the text into \Q...\E. You can switch the automatic evaluation of wildcards or regular expression on and off in - LibreOffice Calc - Calculate.

warning

When using functions where one or more arguments are search criteria strings that represents a regular expression, the first attempt is to convert the string criteria to numbers. For example, ".0" will convert to 0.0 and so on. If successful, the match will not be a regular expression match but a numeric match. However, when switching to a locale where the decimal separator is not the dot makes the regular expression conversion work. To force the evaluation of the regular expression instead of a numeric expression, use some expression that can not be misread as numeric, such as ".[0]" or ".\0" or "(?i).0".


Syntax

DSUM(データベース; データベースフィールド; 検索条件)

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 (from the first row of Database range), place quotation marks around the header name.

Example

Joe の誕生日パーティに参加した子供たちのうち、2 年生全員の通学路の合計距離を求めるには (上にスクロールしてください)、次の数式をセル B16 に入力します:

=DSUM(A1:E10;"Distance to School";A13:E14)

行 14 の Grade には、2 を入力します。2 年生の子供たち全員の学校への距離の合計 (1950) が表示されます。

DVAR

DVAR は、データベースにおいて検索条件を満たす行のうち、データベースフィールドの値の標本をとって、平方偏差を計算します。つまり、DVAR はレコードをデータの標本として扱います。ただし、1000 人に満たない標本だけでは本当の典型にはなり得ません。

The search supports wildcards or regular expressions. With regular expressions enabled, you can enter "all.*", for example to find the first location of "all" followed by any characters. If you want to search for a text that is also a regular expression, you must either precede every character with a "\" character, or enclose the text into \Q...\E. You can switch the automatic evaluation of wildcards or regular expression on and off in - LibreOffice Calc - Calculate.

warning

When using functions where one or more arguments are search criteria strings that represents a regular expression, the first attempt is to convert the string criteria to numbers. For example, ".0" will convert to 0.0 and so on. If successful, the match will not be a regular expression match but a numeric match. However, when switching to a locale where the decimal separator is not the dot makes the regular expression conversion work. To force the evaluation of the regular expression instead of a numeric expression, use some expression that can not be misread as numeric, such as ".[0]" or ".\0" or "(?i).0".


Syntax

DVAR(データベース; データベースフィールド; 検索条件)

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 (from the first row of Database range), place quotation marks around the header name.

Example

年齢が同じ子供たち全員の体重の平方偏差を求めるには (上にスクロールしてください)、次の数式をセル B16 に入力します

=DVAR(A1:E10;"Weight";A13:E14)

行 14 の Age には、7、8、9 などを順に入力します。結果として、この年齢の子供たち全員の体重値の分散が表示されます。

DVARP

DVARP は、データベースにおいて検索条件を満たす行のうち、データベースフィールドのすべての値を使用して、平方偏差を計算します。つまり、DVARP はレコードを母集団全体として扱います。

The search supports wildcards or regular expressions. With regular expressions enabled, you can enter "all.*", for example to find the first location of "all" followed by any characters. If you want to search for a text that is also a regular expression, you must either precede every character with a "\" character, or enclose the text into \Q...\E. You can switch the automatic evaluation of wildcards or regular expression on and off in - LibreOffice Calc - Calculate.

warning

When using functions where one or more arguments are search criteria strings that represents a regular expression, the first attempt is to convert the string criteria to numbers. For example, ".0" will convert to 0.0 and so on. If successful, the match will not be a regular expression match but a numeric match. However, when switching to a locale where the decimal separator is not the dot makes the regular expression conversion work. To force the evaluation of the regular expression instead of a numeric expression, use some expression that can not be misread as numeric, such as ".[0]" or ".\0" or "(?i).0".


Syntax

DVARP(データベース; データベースフィールド; 検索条件)

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 (from the first row of Database range), place quotation marks around the header name.

Example

Joe の誕生日会に招待された同年齢の子供全員の体重の標本分散を検査します (上にスクロールしてください)。B16 に次の数式を入力します:

=DVARP(A1:E10;"Weight";A13:E14)

行 14 の Age には、7、8、9 などを順に入力します。Joe の誕生日パーティーに参加する、この年齢の子供たち全員の体重値の分散が表示されます。

ご支援をお願いします!