Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
获取项目在SQL中所属的百分比_Sql_Statistics_Google Bigquery_Percentile - Fatal编程技术网

获取项目在SQL中所属的百分比

获取项目在SQL中所属的百分比,sql,statistics,google-bigquery,percentile,Sql,Statistics,Google Bigquery,Percentile,我试图整理一些简单的统计数据,但仍坚持根据作者的总分计算其所属的百分比: select [by] author, count(*) count, sum(score) sum_score, quantiles(sum(score), 101) percentile_sum_score, from [bigquery-public-data:hacker_news.stories] group by author 此代码在百分位数(sum)得分列中

我试图整理一些简单的统计数据,但仍坚持根据作者的总分计算其所属的百分比:

select
    [by] author,
    count(*) count,
    sum(score) sum_score,
    quantiles(sum(score), 101) percentile_sum_score,
from
    [bigquery-public-data:hacker_news.stories]
group by
    author
此代码在
百分位数(sum)得分
列中返回每个作者的
总和(得分)
(定义为
分位数(总和(得分),101)
)。但不是作者相对于其他作者的百分位

这种情况发生在中,一些常规函数不可用()

有没有办法获得正确的统计数据?

您可能正在寻找函数
下面是您的示例的可能用途

SELECT
    author,
    [count],
    sum_score,
    PERCENT_RANK() OVER(ORDER BY sum_score DESC) percentile_sum_score,
FROM (
  SELECT
    [by] author,
    COUNT(1) [count],
    SUM(score) sum_score,
  FROM [bigquery-public-data:hacker_news.stories]
  GROUP BY author
)