メインコンテンツまでスキップ
バージョン: Latest-3.4

array_difference

配列の各要素からその次の要素を引くことで、配列内の隣接する要素間の差を計算し、その差を含む配列を返します。

Syntax

array_difference(input)

Parameters

input: 隣接する要素間の差を計算したい配列。

Return value

input パラメータで指定した配列と同じデータ型と長さの配列を返します。

Examples

Example 1:

mysql> SELECT array_difference([342, 32423, 213, 23432]);
+-----------------------------------------+
| array_difference([342,32423,213,23432]) |
+-----------------------------------------+
| [0,32081,-32210,23219] |
+-----------------------------------------+

Example 2:

mysql> SELECT array_difference([342, 32423, 213, null, 23432]);
+----------------------------------------------+
| array_difference([342,32423,213,NULL,23432]) |
+----------------------------------------------+
| [0,32081,-32210,null,null] |
+----------------------------------------------+

Example 3:

mysql> SELECT array_difference([1.2, 2.3, 3.2, 4324242.55]);
+--------------------------------------------+
| array_difference([1.2,2.3,3.2,4324242.55]) |
+--------------------------------------------+
| [0,1.1,0.9,4324239.35] |
+--------------------------------------------+

Example 4:

mysql> SELECT array_difference([false, true, false]);
+----------------------------------------+
| array_difference([FALSE, TRUE, FALSE]) |
+----------------------------------------+
| [0,1,-1] |
+----------------------------------------+