我有一个我生成的表格,其中信息每天汇总到汇总我有第二个表格,可以将其视为日历表格,它允许我在加入表格时获取汇总的周数
表格中的日期都是整数,例如 20130501 (YYYYMMDD)
当我在下面创建 SQL(通用)时,它工作正常,但现在我想安排这个脚本每周运行一次以获取前一周并收到错误
脚本工作正常
SELECT *
FROM TABLE_1 as sample
INNER JOIN TABLE_2 as calendar
ON sample.day = calendar.day
WHERE sample.day >= 20130501
AND sample.day <= 20130507
脚本失败
SELECT *
FROM TABLE_1 as sample
INNER JOIN TABLE_2 as calendar
ON sample.day = calendar.day
-- >= Previous Monday Last week
WHERE sample.day >= CAST(CAST(((DATE-DAYOFWEEK(DATE)-5) (FORMAT 'YYYYMMDD')) AS CHAR(8)) AS INT)
-- <= Previous Sunday Last week
AND sample.day <= CAST(CAST(((DATE-DAYOFWEEK(DATE)+ 1) (FORMAT 'YYYYMMDD')) AS CHAR(8)) AS INT)
我在第二个脚本上收到的错误消息是
Teradata ODBC Teradata 驱动程序语法错误:预期介于 ')' 和 '-' 之间
谢谢大家的时间这几天一直困扰着我