Calculate Median for each group in AWS Athena table

强颜欢笑 提交于 2021-02-11 15:03:33

问题


Below is the schema for the athena table

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

It throws error

 SYNTAX_ERROR: line 1:8: Function median not registered

Any help? Or if some alternative query would be great


回答1:


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:

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.



来源:https://stackoverflow.com/questions/64962634/calculate-median-for-each-group-in-aws-athena-table

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!