ifnull和日期

nuypyhwy  于 2021-08-09  发布在  Java
关注(0)|答案(2)|浏览(419)

我有下面的select语句

FIRST_VALUE(date) OVER (PARTITION BY client_ID ORDER BY date ASC),0) AS first_conversion_date,

如果没有日期,我希望它返回一个字符串或整数。
我试过这个例子:

ifnull(FIRST_VALUE(date) OVER (PARTITION BY client_ID ORDER BY date ASC),0) AS first_conversion_date,

但出现以下错误: No matching signature for function IFNULL for argument types: DATE, INT64. Supported signature: IFNULL(ANY, ANY) at [26:9] Learn More about BigQuery SQL Functions. 我该怎么办?

2ledvvac

2ledvvac1#

似乎要避免结果中出现空值
显然,不能在同一输出列中将日期类型与字符串或int64混合,所以需要将所有内容转换为字符串,如下面的示例所示

IFNULL(CAST(FIRST_VALUE(DATE) OVER (PARTITION BY client_ID ORDER BY DATE ASC) AS STRING), 'whatever default value you have in mind') AS first_conversion_date
5us2dqdw

5us2dqdw2#

你想要什么 coalesce() ?

COALESCE(FIRST_VALUE(date) OVER (PARTITION BY client_ID ORDER BY date ASC),0)

相关问题