在 Presto 上计算日期和周末日期 [英] Calculate date and weekending date on Presto
本文介绍了在 Presto 上计算日期和周末日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
将日、月和年作为表中的整数列,根据这些值计算日期和周末日期.
Given day, month and year as integer columns in the table, calculate the date and weekending date from these values.
我尝试了以下
select date_parse(cast (2020 as varchar)||cast (03 as varchar)||cast (02 as varchar),'%Y%m%d')
返回错误消息INVALID_FUNCTION_ARGUMENT:格式无效:202032"太短"
returns an error saying "INVALID_FUNCTION_ARGUMENT: Invalid format: "202032" is too short"
推荐答案
最简单的方法是使用 format()
+ cast
to date
:
The simplest way is to use format()
+ cast
to date
:
presto> SELECT CAST(format('%d-%d-%d', 2020, 3, 31) AS date);
_col0
------------
2020-03-31
由于 Athena 仍然基于 Presto .172,所以它还没有这个功能,所以你可以不用 format
来做同样的事情:
Since Athena is still based on Presto .172, it doesn't have this function yet, so you can do the same without format
:
presto> SELECT CAST(CAST(2020 AS varchar) || '-' || CAST(3 AS varchar) || '-' || CAST(31 AS varchar) AS date);
_col0
------------
2020-03-31
这篇关于在 Presto 上计算日期和周末日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文