Sql 如何计算四分位范围的范围
给定一个表,我需要计算25%和75%四分位数的四分位数范围——它应该是一个输出差 注意:“gini”只是我的表rdata中的一列;我不打算在这里输入我的数据,因为数据很长,但我只需要弄清楚如何通过percentile_disc/cont输出差异Sql 如何计算四分位范围的范围,sql,postgresql,group-by,percentile,Sql,Postgresql,Group By,Percentile,给定一个表,我需要计算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_di
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()指定组内的
您需要函数percentile_disc,因为错误消息清楚地表明您使用的是MySQL还是Postgresql?@jarlh:从错误消息中,这是Postgres。我删除了MySQL标签。而你,postgres库是否指定了这个?为什么在组内为每个one@Isabelle这些文件确实如此,但可能不够明确。percentile\u dist()
聚合函数本身不起作用。它需要一个组内的(orderby)
跟随它,以便调用工作。
select percentile_disc(0.75) within group (order by gini) -
percentile_disc(0.25) within group (order by gini)
from rdata;