admin管理员组

文章数量:1794759

redshift DATE

redshift DATE_TRUNC函数 查询日期上个月的26号到当前月的26号

代码语言:javascript代码运行次数:0运行复制
# redshift脚本
# 2023-08-01 00:00:00.000
select DATE_TRUNC('month',current_date - INTERVAL '2 month')
# 2023-08
select left(DATE_TRUNC('month',current_date - INTERVAL '2 month'),7)
# 2023-08-26
select date(left(DATE_TRUNC('month',current_date - INTERVAL '2 month'),7)+'-26')

# 上上个月26号到上个月的26号
select date(left(DATE_TRUNC('month',current_date - INTERVAL '2 month'),7)+'-26')
# 2023-09-26
select date(left(DATE_TRUNC('month',current_date - INTERVAL '1 month'),7)+'-26')


# 正解
# 2023-09-26
select date(left(DATE_TRUNC('month',current_date - INTERVAL '1 month'),7)+'-26')
# 2023-10-26
select date(left(DATE_TRUNC('month',current_date - INTERVAL '0 month'),7)+'-26')

# 正解
# 2023-10-01 00:00:00.000
select DATE_TRUNC('month',current_date)
# 2023-10
select left(DATE_TRUNC('month',current_date),7)
# 2023-10-26
select date(left(DATE_TRUNC('month',current_date),7)+'-26')
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。 原始发表:2023-10-28,如有侵权请联系 cloudcommunity@tencent 删除dateselect函数脚本

本文标签: redshift DATE