简体   繁体   English

DATE_TRUNC 从周日开始 SQL presto (Athena)

[英]DATE_TRUNC Starting on Sunday for SQL presto (Athena)

For as simple as this question may sound, I have not been able to find a straight forward solution.尽管这个问题听起来很简单,但我一直无法找到直接的解决方案。 I am using AWS Athena, which is a presto engine to my knowledge.我正在使用 AWS Athena,据我所知这是一个 presto 引擎。

I have variable 'created_at' which is a TIMESTAMP.我有一个时间戳变量“created_at”。 How can I get DATE_TRUNC('week', created_at) to start in SUNDAY instead of MONDAY?如何让DATE_TRUNC('week', created_at)在星期天而不是星期一开始?

I've seen documentation concerning %V or %X as possible solutions, but not sure where in the function to introduce this, that is, if it is the proper solution.我看过有关 %V 或 %X 作为可能解决方案的文档,但不确定在 function 中的何处介绍它,也就是说,它是否是正确的解决方案。

Essentially I want to count sales by week starting on SUNDAY ending on SATURDAY, I will be grouping by weeK本质上,我想按周计算销售额,从周日开始到周六结束,我将按周分组

GROUP BY DATE_TRUNC('week', created_at) 

You could use them in date_format function: date_format(created_at, '%X%V') (and use the result to group), but unfortunately they are not supported by presto at the moment.您可以在date_format function: date_format(created_at, '%X%V')中使用它们(并使用结果进行分组),但不幸的是,目前 presto 不支持它们。

As a workaround you can just add one day:作为一种解决方法,您可以只添加一天:

select week(created_at + interval '1' day)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM