percentile_cont 计算中位数时的签名错误

huangapple go评论136阅读模式
英文:

percentile_cont signature error when calculating median

问题

我有一个名为“masterdata”的表,其结构如下:

user_eng_time,day,user_pseudo_id

我正在运行以下代码:

select percentile_cont(x,0.5) over () as median_time_in_seconds
from( 
select round(user_eng_time/1000) from masterdata 
) as x

我得到了以下错误:

聚合函数PERCENTILE_CONT没有匹配的签名,参数类型为: STRUCT<FLOAT64>,FLOAT64。支持的签名有: PERCENTILE_CONT(FLOAT64, FLOAT64); PERCENTILE_CONT(NUMERIC, NUMERIC); PERCENTILE_CONT(BIGNUMERIC, BIGNUMERIC) 在 [55:8] 处
英文:

Hi I have a table "masterdata" with the following structure:

user_eng_time, day, user_pseudo_id

I am running the following code:

select percentile_cont(x,0.5) over () as median_time_in_seconds
from( 
select round(user_eng_time/1000) from masterdata 
) as x

I am getting the following error:

No matching signature for aggregate function PERCENTILE_CONT for argument types: STRUCT&lt;FLOAT64&gt;, FLOAT64. Supported signatures: PERCENTILE_CONT(FLOAT64, FLOAT64); PERCENTILE_CONT(NUMERIC, NUMERIC); PERCENTILE_CONT(BIGNUMERIC, BIGNUMERIC) at [55:8]

答案1

得分: 2

percentile_cont 期望的第一个参数是一个浮点数值,而不是一个表格。在您的情况下,您可以使用 x.col 来引用表格 x 和列 col

With masterdata as (
  Select 10000*rand() as user_eng_time 
  from unnest(generate_array(1,100))
  )

select *,percentile_cont(x.col,0.5) over () as median_time_in_seconds
from( 
select round(user_eng_time/1000) as col from masterdata 
) as x
英文:

percentile_cont expects as first entry a float value and not a table. In your case, you can use x.col to reference on table x and the column col.

With masterdata as (
  Select 10000*rand() as user_eng_time 
  from unnest(generate_array(1,100))
  )

select *,percentile_cont(x.col,0.5) over () as median_time_in_seconds
from( 
select round(user_eng_time/1000) as col from masterdata 
) as x

huangapple
  • 本文由 发表于 2023年5月28日 14:53:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/76350299.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定