【问题标题】:How to compute range of quartile range如何计算四分位数范围
【发布时间】:2020-11-26 02:57:27
【问题描述】:

给定一个表格,我需要计算 25% 和 75% 四分位数的四分位数范围——它应该只是一个输出差值。

注意:'gini' 只是我的表 rdata 中的一列;由于数据很长,我这里就不输入数据了,但我只需要弄清楚如何通过 percentile_disc/cont 输出差异。

select percentile_disc(0.75)-percentile_disc(0.25) within group (order by gini) from rdata;

输出错误:

LINE 1: select percentile_disc(0.75)-percentile_disc(0.25) within gr...
               ^
HINT:  No function matches the given name and argument types. You might need to add explicit type casts..

我尝试转换 percentile_disc::numeric 但这也给了我一个错误。

【问题讨论】:

  • 你需要函数 percentile_disc 错误信息说得很清楚
  • 你使用的是 MySQL 还是 Postgresql?
  • @jarlh:从错误消息来看,这是 Postgres。我删除了 MySQL 标签。

标签: sql postgresql group-by percentile


【解决方案1】:

问题是必须为每个percentile_disc() 指定within group

select percentile_disc(0.75) within group (order by gini) - 
          percentile_disc(0.25) within group (order by gini)
  from rdata;

【讨论】:

  • 比你,postgres 库是否指定了这个?为什么在为每个人指定的组内
  • @Isabelle 文档可以,但可能不够明确。 percentile_dist() 聚合函数本身并不独立。它需要within group (order by <some column>) 跟随它才能使调用起作用。
猜你喜欢
  • 2021-01-07
  • 1970-01-01
  • 2020-12-15
  • 2015-04-12
  • 2016-03-22
  • 2021-08-16
  • 1970-01-01
  • 2021-12-26
  • 2020-06-06
相关资源
最近更新 更多