【发布时间】:2021-10-11 09:09:38
【问题描述】:
对于每个行政区,每个十字路口受伤人数的第 90 个百分位数是多少?
我有 borough 列,其中包含受伤人数的列,我将其汇总为一列。我需要找到受伤人数的 90%。它只给了我一个价值。我需要为每一行获取不同的值(或者我错了吗?)
select distinct borough,count(num_of_injured) as count_all, PERCENTILE_CONT(num_of_injured, 0.9 RESPECT NULLS) OVER() AS percentile90
from`bigquery-public-data.new_york.nypd_mv_collisions` c cross join
unnest(array[number_of_persons_injured,number_of_pedestrians_injured,number_of_motorist_killed,number_of_cyclist_injured]
)num_of_injured
where borough!=''
group by borough,num_of_injured
order by count_all desc
limit 10;
感谢您的帮助!
【问题讨论】:
标签: sql group-by google-bigquery subquery percentile