ARRAY_COMPACY
array_compact
array_compact
描述
从数组中删除连续的重复元素,结果值的顺序由源数组中的顺序决定。
语法
Array<T> array_compact(arr)
参数
arr
— 需要处理的数组。
返回值
不存在连续重复元素的数组。
Type: Array.
举例
select array_compact([1, 2, 3, 3, null, null, 4, 4]);
+----------------------------------------------------+
| array_compact(ARRAY(1, 2, 3, 3, NULL, NULL, 4, 4)) |
+----------------------------------------------------+
| [1, 2, 3, NULL, 4] |
+----------------------------------------------------+
select array_compact(['aaa','aaa','bbb','ccc','ccccc',null, null,'dddd']);
+-------------------------------------------------------------------------------+
| array_compact(ARRAY('aaa', 'aaa', 'bbb', 'ccc', 'ccccc', NULL, NULL, 'dddd')) |
+-------------------------------------------------------------------------------+
| ['aaa', 'bbb', 'ccc', 'ccccc', NULL, 'dddd'] |
+-------------------------------------------------------------------------------+
select array_compact(['2015-03-13','2015-03-13']);
+--------------------------------------------------+
| array_compact(ARRAY('2015-03-13', '2015-03-13')) |
+--------------------------------------------------+
| ['2015-03-13'] |
+--------------------------------------------------+
keywords
ARRAY,COMPACT,ARRAY_COMPACT