【问题标题】:Calculate Median for each group in AWS Athena table计算 AWS Athena 表中每个组的中位数
【发布时间】:2020-11-23 04:39:40
【问题描述】:

下面是雅典娜表的架构

我希望按标准实验室参数名称和单位计算“参数值”组的中位数。为此,我点击了链接: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

报错

 SYNTAX_ERROR: line 1:8: Function median not registered

有什么帮助吗?或者如果一些替代查询会很棒

【问题讨论】:

  • 雅典娜不是红移
  • Thisthis 可能会有所帮助。如果您只是谷歌“sql 计算中位数”,还有很多其他可用的解决方案

标签: sql amazon-web-services group-by amazon-athena median


【解决方案1】:

Athena 基于 Presto 0.172 - 您可以在 AWS DML Queries, Functions, and Operators 中查看所有支持的功能。我猜你可以使用approx_percentile(x, percentage)approx_percentile(x, w, percentage, accuracy),见Presto Aggregate Functions

返回给定百分比的 x 的所有输入值的近似百分位数。百分比的值必须介于 0 和 1 之间,并且对于所有输入行必须是常数。

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

请记住,这是一个近似聚合函数。

【讨论】:

    猜你喜欢
    • 2021-02-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-18
    • 1970-01-01
    • 2020-11-22
    • 2022-12-01
    • 2014-01-24
    相关资源
    最近更新 更多