英文:
Passing Dynamic Date Part to Date_Add in BigQuery
问题
有没有办法将一个动态字符串传递给在date_add函数中整数之后的日期部分?
即:
date_add('2023-01-01', interval 7 {dynamic_date_part})
其中{dynamic_date_part}可以是'day'、'week'、'month'等?
我尝试过这样做,但它会拒绝在那里放置的任何内容,只显示"unexpected"。
英文:
Is there a way to pass a dynamic string to the date part that comes after the integer in the date_add function?
I.e.
date_add('2023-01-01', interval 7 {dynamic_date_part})
where {dynamic_date_part} could be 'day', 'week', 'month' etc?
I tried this but it rejects anything that gets put there as just "unexpected"
答案1
得分: 1
你可以使用以下查询来添加动态日期部分:
select date_add(dte, interval n {dynamic_date_part}) as date
from (select current_date as dte, 1 as n union all
SELECT CURRENT_DATE, 2)
其中,1
和 2
在以下部分表示时间间隔的日/周/月:
from (select current_date as dte, 1 as n union all
SELECT CURRENT_DATE, 2)
英文:
You can use this query to add the dynamic date part:
select date_add(dte, interval n {dynamic_date_part}) as date
from (select current_date as dte, 1 as n union all
SELECT CURRENT_DATE, 2)
As 1
and 2
in
from (select current_date as dte, 1 as n union all
SELECT CURRENT_DATE, 2)
represent the day/week/month of interval.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论