简体   繁体   English

计算 AWS Athena 表中每个组的中位数

[英]Calculate Median for each group in AWS Athena table

Below is the schema for the athena table下面是 athena 表的架构

在此处输入图片说明

I wish to calculate median for 'parameter_value' group by standard_lab_parameter_name & units.我希望通过 standard_lab_parameter_name 和单位计算“parameter_value”组的中位数。 For this I followed link : https://docs.aws.amazon.com/redshift/latest/dg/r_MEDIAN.html But on running the query为此,我点击了链接: https : //docs.aws.amazon.com/redshift/latest/dg/r_MEDIAN.html但是在运行查询时

select median(parameter_value) from table_name group by standard_lab_parameter_name, units

It throws error它抛出错误

 SYNTAX_ERROR: line 1:8: Function median not registered

Any help?有什么帮助吗? Or if some alternative query would be great或者如果一些替代查询会很棒

Athena is based on Presto 0.172 - you can see all supported functions in AWS DML Queries, Functions, and Operators . Athena 基于 Presto 0.172 - 您可以在AWS DML 查询、函数和运算符中查看所有支持的函数。 I guess you could use approx_percentile(x, percentage) or approx_percentile(x, w, percentage, accuracy) , see Presto Aggregate Functions :我猜您可以使用approx_percentile(x, percentage) approx_percentile(x, w, percentage, accuracy) approx_percentile(x, percentage)approx_percentile(x, w, percentage, accuracy) ,请参阅Presto 聚合函数

Returns the approximate percentile for all input values of x at the given percentage.以给定百分比返回 x 的所有输入值的近似百分位数。 The value of percentage must be between zero and one and must be constant for all input rows.百分比的值必须介于 0 和 1 之间,并且对于所有输入行必须是常数。

select approx_percentile(parameter_value,0.5) 
from table_name 
group by standard_lab_parameter_name, units

Keep in mind that this is a Approximate Aggregate Functions.请记住,这是一个近似聚合函数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM