尝试在Big Query中运行时,为什么在此sql中得到意外的关键字INTERVAL?

时间:2019-03-29 02:14:38

标签: sql google-bigquery

我得到了这个sql,而我试图在BigQuery中运行它。我收到此错误:

意外的关键字INTERVAL

SELECT studio."Location" as location ,CONCAT(users.first_name, ',', users.last_name) AS username , COUNT(events.created_at) AS events    
FROM xxx    
JOIN zzz ON z_kf_asset = asset.z_kp    
JOIN client ON production.z_kf_client = client.z_kp    
JOIN studio ON client.z_kf_studio = studio.z_kp    
JOIN events ON events.asset_id = asset.z_kp    
JOIN users ON events.user_id = users."id"    
WHERE post_history IS NOT NULL    
AND events.created_at BETWEEN LOCALTIMESTAMP - INTERVAL '7 days' AND LOCALTIMESTAMP    
AND client.display_name = 'xxxxx'    
AND events.description = 'xxxxxxxx'    
GROUP BY location, username

非常感谢您的帮助

1 个答案:

答案 0 :(得分:0)

尼克在评论中给出了正确答案。在此处转录以保持完整性:

代替:

localtimestamp - INTERVAL '7 days'

要做:

TIMESTAMP_SUB(localtimestamp, INTERVAL 7 DAY)

例如:

SELECT '2018-01-9' BETWEEN TIMESTAMP_SUB(localtimestamp, INTERVAL 7 DAY) AND localtimestamp
FROM (SELECT TIMESTAMP('2018-01-15') localtimestamp)