英文:
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<FLOAT64>, 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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论