APPROX_QUANTILES
函数 :) 文档中的一个示例如下:#standardSQL
SELECT APPROX_QUANTILES(x, 2) AS approx_quantiles
FROM UNNEST([NULL, NULL, 1, 1, 1, 4, 5, 6, 7, 8, 9, 10]) AS x;
+------------------+
| approx_quantiles |
+------------------+
| [1, 5, 10] |
+------------------+
请注意它返回的是一个数组,但如果你想把数组中的元素逐行显示,你可以对结果进行展开:
#standardSQL
SELECT
quant, offset
FROM UNNEST((
SELECT APPROX_QUANTILES(x, 2) AS quants
FROM UNNEST([NULL, NULL, 1, 1, 1, 4, 5, 6, 7, 8, 9, 10]) AS x
)) AS quant WITH OFFSET
ORDER BY offset;