为什么较低的分位数大于较高的分位数?

时间:2017-06-27 19:06:18

标签: google-bigquery

这是我的query

SELECT
  APPROX_QUANTILES(JSON_EXTRACT_SCALAR(lighthouse,
      '$.audits.first-meaningful-paint.rawValue'),1000)[OFFSET(100)] AS p10,
  APPROX_QUANTILES(JSON_EXTRACT_SCALAR(lighthouse,
      '$.audits.first-meaningful-paint.rawValue'),1000)[OFFSET(250)] AS p25,
  APPROX_QUANTILES(JSON_EXTRACT_SCALAR(lighthouse,
      '$.audits.first-meaningful-paint.rawValue'),1000)[OFFSET(500)] AS p50,
  APPROX_QUANTILES(JSON_EXTRACT_SCALAR(lighthouse,
      '$.audits.first-meaningful-paint.rawValue'),1000)[OFFSET(750)] AS p75,
  APPROX_QUANTILES(JSON_EXTRACT_SCALAR(lighthouse,
      '$.audits.first-meaningful-paint.rawValue'),1000)[OFFSET(900)] AS p90
FROM
  `httparchive.har.2017_06_01_android_pages`
WHERE
  lighthouse != 'null'

结果:

Row p10     p25     p50     p75     p90  
1   13223.9 2904.2  4851.2  6817    8352.1

为什么p10(13223.9)大于p90(8352.1)?

编辑:这似乎是BigQuery的一个短暂问题。我现在得到预期的结果。提起了一个错误。

1 个答案:

答案 0 :(得分:2)

输入是字符串,而不是浮点数:)如果你想要浮点排序,你需要转换:

SELECT
  quantiles[OFFSET(100)] AS p10,
  quantiles[OFFSET(250)] AS p25,
  quantiles[OFFSET(500)] AS p50,
  quantiles[OFFSET(750)] AS p75,
  quantiles[OFFSET(900)] AS p90
FROM (
  SELECT
    APPROX_QUANTILES(CAST(JSON_EXTRACT_SCALAR(lighthouse,
        '$.audits.first-meaningful-paint.rawValue') AS FLOAT64),1000) AS quantiles
  FROM
    `httparchive.har.2017_06_01_android_pages`
  WHERE
    lighthouse != 'null'
);
+--------+--------+--------+--------+---------+
|  p10   |  p25   |  p50   |  p75   |   p90   |
+--------+--------+--------+--------+---------+
| 2578.7 | 3944.1 | 5781.3 | 8092.4 | 10785.5 |
+--------+--------+--------+--------+---------+