获取项目在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
)