tencent cloud

Cloud Log Service

General Aggregate Function

Download
포커스 모드
폰트 크기
마지막 업데이트 시간: 2026-06-05 12:58:51
This document describes the basic syntax and examples of aggregate functions.

Function Description

An aggregate function calculates a set of values and returns the calculation result. CLS supports the following aggregate functions.
Note:
In CLS analysis statements, strings must be included in single quotes (''), and field names and column names are unsigned or included in double quotes (""). For example, 'status' indicates the string 'status', and status or "status" indicates the log field status.
Function
Description
Example

arbitrary(KEY)

Returns an arbitrary non-null value of the KEY column.
* | SELECT arbitrary(request_method) AS request_method

avg(KEY)

Returns the average (arithmetic mean) of the KEY column.
* | SELECT AVG(request_time)

bitwise_and_agg(KEY)

Returns the result of the bitwise AND operation on all values in the target column.
* | SELECT bitwise_and_agg(status)

bitwise_or_agg(KEY)

Returns the result of the bitwise OR operation on all values in the target column.
* | SELECT bitwise_or_agg(request_length)

checksum(KEY)

Calculates the checksum value of the target column. The returned result is a binary string.
* | SELECT checksum(request_method) AS request_method

count(*)

Returns the number of input rows.
* | SELECT COUNT(*) WHERE http_status >200

count(1)

Returns the number of input rows. This function is equivalent to count(*).
* | SELECT COUNT(1)

count(KEY)

Returns the number of non-null input values of the KEY column.
* | SELECT COUNT(request_time) WHERE request_time >5.0

count_if(boolean)

Returns the number of logs that meet specified conditions.
* | select count_if(returnCode>=400) as errorCounts

geometric_mean(KEY)

Returns the geometric mean of KEY, which cannot contain negative numbers; otherwise, the result will be NaN.
* | SELECT geometric_mean(request_time) AS request_time

max(KEY)

Returns the maximum value of KEY.
* | SELECT MAX(request_time) AS max_request_time

max_by(x,y)

Returns the value of x associated with the maximum value of y over all input values.
* | SELECT MAX_BY(request_method, request_time) AS method

max_by(x,y,n)

Returns n values of x associated with the n largest of all input values of y in descending order of y.
* | SELECT max_by(request_method, request_time, 3) AS method

min(KEY)

Returns the minimum value of KEY.
* | SELECT MIN(request_time) AS min_request_time

min_by(x,y)

Returns the value of x associated with the minimum value of y over all input values.
* | SELECT min_by(request_method, request_time) AS method

min_by(x,y,n)

Returns n values of x associated with the n smallest of all input values of y in descending order of y.
* | SELECT min_by(request_method, request_time, 3) AS method

sum(KEY)

Returns the sum of the KEY column.
* | SELECT SUM(body_bytes_sent) AS sum_bytes

bool_and(boolean)

Returns TRUE if all logs meet the specified condition or FALSE otherwise.
* | select bool_and(returnCode>=400)

bool_or(boolean)

Returns TRUE if any log meets the specified condition or FALSE otherwise.
* | select bool_or(returnCode>=400)

every(boolean)

Equivalent to bool_and(boolean).
* | select every(returnCode>=400)
histogram(KEY)
Returns a map containing the count of occurrences for each input value.
* | SELECT histogram(http_code)
map_agg(KEY, VALUE)
Returns a map created from the input key/value pairs.
* | SELECT map_agg(host,http_code)
map_union(KEY)
Returns the union of all input maps. If a key appears in multiple input maps, the value for that key in the resulting map comes from any one of the input maps.
* | SELECT map_union(m) FROM (VALUES (map(array['a','b'], array[1,2])), (map(array['b','c'], array[20,3]))) t(m)
multimap_agg(KEY, VALUE)
Returns a multimap created from the input key/value pairs. Each key can be associated with multiple values.
* | SELECT multimap_agg(host,http_code)

Field description

Parameter
Description
KEY
Name of the log field for which the statistics feature is enabled in the Index Configuration - Key-Value Index section. The value can also be the result of the four basic arithmetic operations on multiple numeric fields or the query result of a nested subquery.
x
The parameter value can be of any data type.
y
The parameter value can be of any data type.
n
An integer greater than 0.


도움말 및 지원

문제 해결에 도움이 되었나요?

피드백