计算AWS Athena表中每个组的中位数 [英] Calculate Median for each group in AWS Athena table

查看:138
本文介绍了计算AWS Athena表中每个组的中位数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是雅典娜表的架构

我希望通过standard_lab_parameter_name&计算"parameter_value"组的中位数单位.为此,我点击了以下链接: https://docs.aws.amazon.com/redshift/latest/dg/r_MEDIAN.html 但是在运行查询时

I wish to calculate median for 'parameter_value' group by standard_lab_parameter_name & units. For this I followed link : https://docs.aws.amazon.com/redshift/latest/dg/r_MEDIAN.html But on running the query

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

它引发错误

 SYNTAX_ERROR: line 1:8: Function median not registered

有帮助吗?或者,如果有其他替代查询会很好

Any help? Or if some alternative query would be great

推荐答案

雅典娜基于Presto 0.172-您可以在

Athena is based on Presto 0.172 - you can see all supported functions in AWS DML Queries, Functions, and Operators. I guess you could use approx_percentile(x, percentage) or approx_percentile(x, w, percentage, accuracy), see Presto Aggregate Functions:

以给定的百分比返回x的所有输入值的近似百分位数.百分比的值必须在0到1之间,并且对于所有输入行都必须是恒定的.

Returns the approximate percentile for all input values of x at the given percentage. The value of percentage must be between zero and one and must be constant for all input rows.

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.

这篇关于计算AWS Athena表中每个组的中位数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆