使い方:
count()
count(DISTINCT column_name)count は、各グループまたは結果セットの行数を返す集約関数です。
count は、各列の異なる(一意の)値の数を数えるときにも使えます。
例:
-- return the total number of rows
count()
-- return the number of different values in the column
count(DISTINCT column_name)使い方:
sum([DISTINCT] column_name)sum は、各グループまたは結果セットのすべての行にわたる列値の合計を返す集約関数です。DISTINCT にも対応しており、その場合は列内の一意の値だけを合計します。
例:
-- return the total cost of all items
sum(item_cost)
-- return the total of all unique item costs
sum(DISTINCT item_cost)使い方:
avg([DISTINCT] column_name)avg は、各グループまたは結果セットのすべての行にわたる列値の平均を返す集約関数です。DISTINCT にも対応しており、その場合は列内の一意の値だけを平均します。
例:
-- return the mean item cost
avg(item_cost)
-- return the mean of unique item costs
avg(DISTINCT item_cost)使い方:
min(column_name)min は、すべての行にわたる列の最小値を返す集約関数です。
例:
-- return the minimum item cost
min(item_cost)使い方:
max(column_name)max は、すべての行にわたる列の最大値を返す集約関数です。
例:
-- return the maximum item cost
max(item_cost)使い方:
quantileExactWeighted(q)(column_name, weight_column_name)quantileExactWeighted は、各グループまたは結果セットの指定列について、q 番目の分位点の値を返す集約関数です。各行は weight_column_name の値で重み付けされます。通常は _sample_interval を使います(詳細は サンプリング を参照してください)。
例:
-- estimate the median value of <double1>
quantileExactWeighted(0.5)(double1, _sample_interval)
-- in a table of query times, estimate the 95th centile query time
quantileExactWeighted(0.95)(query_time, _sample_interval)後方互換のため、quantileWeighted(q, column_name, weight_column_name) としても使えます。
使い方:
argMax(arg, val)argMax は、val が最大となる行の arg 値を返す集約関数です。
val が最大となる arg が複数ある場合は、そのうちのいずれかが返されます。
例:
-- find the <blob1> value for the row with the highest <double1>
argMax(blob1, double1)
-- find the <blob1> value from the most heavily sampled row
argMax(blob1, _sample_interval)使い方:
argMin(arg, val)argMin は、val が最小となる行の arg 値を返す集約関数です。
val が最小となる arg が複数ある場合は、そのうちのいずれかが返されます。
例:
-- find the <blob1> value for the row with the lowest <double1>
argMin(blob1, double1)
-- find the <blob1> value from the least heavily sampled row
argMin(blob1, _sample_interval)使い方:
first_value(column_name)first_value は、指定した列の最初の値を返す集約関数です。
例:
-- find the oldest value of <blob1>
SELECT first_value(blob1) FROM my_dataset ORDER BY timestamp ASC使い方:
last_value(column_name)last_value は、指定した列の最後の値を返す集約関数です。
例:
-- find the oldest value of <blob1>
SELECT last_value(blob1) FROM my_dataset ORDER BY timestamp DESC使い方:
topK(N)(column)topK は、列でもっとも多い N 個の値を返す集約関数です。
N は省略可能で、デフォルトは 10 です。
例:
-- find the 10 most common values of <double1>
SELECT topK(double1) FROM my_dataset
-- find the 15 most common values of <blob1>
SELECT topK(15)(blob1) FROM my_dataset使い方:
topKWeighted(N)(column, weight_column)topKWeighted は、別の列で重み付けしたうえで、列でもっとも多い N 個の値を返す集約関数です。
N は省略可能で、デフォルトは 10 です。
例:
-- find the 10 most common values of <double1>, weighted by `_sample_interval`
SELECT topKWeighted(double1, _sample_interval) FROM my_dataset
-- find the 15 most common values of <blob1>, weighted by `_sample_interval`
SELECT topKWeighted(15)(blob1, _sample_interval) FROM my_dataset使い方:
countIf(<expr>)countIf は、指定した式が真になる行だけを数えて、結果セットの行数を返す集約関数です。
例:
-- return the number of rows where `double1` is greater than 5
countIf(double1 > 5)使い方:
sumIf(<expr>, <expr>)sumIf は、2 番目の式が真になる行だけを対象に、1 番目の式の合計を結果セット全体で返す集約関数です。
例:
-- return the sum of column `item_cost` of all items where another column `in_stock` is not zero
sumIf(item_cost, in_stock > 0)使い方:
avgIf(<expr>, <expr>)avgIf は、2 番目の式が真になる行だけを対象に、式の平均を結果セット全体で返す集約関数です。
例:
-- return the mean of column `item_cost` where another column `in_stock` is not zero
avgIf(item_cost, in_stock > 0)