Teradata Select 其中日期 = 上一个 workday/weekday
Teradata Select where date = previous workday/weekday
使用 Teradata 15.1x
我正在尝试 select 前一个工作日的数据。我可以使用
获取前一天
cast(cast(cast(a.date_dim_ck as varchar(13)) as date format 'yyyymmdd') as date format 'mm-dd-yyyy') = current_date - 1
但是当我尝试做一个案例时,在星期一而不是 1 天回顾 3 天(获取星期五的数据,见下文),我得到“[3707] 语法错误,预期类似 'END' ')' 和 '=' 之间的关键字。"
where case
when td_day_of_week(current_date)<>2
then
cast(cast(cast(a.date_dim_ck as varchar(13)) as date format 'yyyymmdd') as date format 'mm-dd-yyyy') = current_date - 1
else
cast(cast(cast(a.date_dim_ck as varchar(13)) as date format 'yyyymmdd') as date format 'mm-dd-yyyy') = current_date - 3
我做错了什么?
您只能使用 case 语句根据另一个条件确定字段的值。请参阅下面的语法。
where cast(cast(cast(a.date_dim_ck as varchar(13)) as date format 'yyyymmdd') as date format 'mm-dd-yyyy') = case
when td_day_of_week(current_date)<>2
then
current_date - 1
else
current_date - 3
end
使用 Teradata 15.1x
我正在尝试 select 前一个工作日的数据。我可以使用
获取前一天cast(cast(cast(a.date_dim_ck as varchar(13)) as date format 'yyyymmdd') as date format 'mm-dd-yyyy') = current_date - 1
但是当我尝试做一个案例时,在星期一而不是 1 天回顾 3 天(获取星期五的数据,见下文),我得到“[3707] 语法错误,预期类似 'END' ')' 和 '=' 之间的关键字。"
where case
when td_day_of_week(current_date)<>2
then
cast(cast(cast(a.date_dim_ck as varchar(13)) as date format 'yyyymmdd') as date format 'mm-dd-yyyy') = current_date - 1
else
cast(cast(cast(a.date_dim_ck as varchar(13)) as date format 'yyyymmdd') as date format 'mm-dd-yyyy') = current_date - 3
我做错了什么?
您只能使用 case 语句根据另一个条件确定字段的值。请参阅下面的语法。
where cast(cast(cast(a.date_dim_ck as varchar(13)) as date format 'yyyymmdd') as date format 'mm-dd-yyyy') = case
when td_day_of_week(current_date)<>2
then
current_date - 1
else
current_date - 3
end