首页 > 解决方案 > sql查询不包括当前日期的数据

问题描述

嗨,我想选择不包括当前日期的最近 3 天数据。

我在雪花上尝试类似下面的东西。

select * from Table where S_date <= DATEADD(DAY, -3, current_date-1) .

但它也包括当前日期。

请帮忙。

标签: sqldatesnowflake-cloud-data-platform

解决方案


在标准 SQL 中,语法为:

where S_date >= current_date - interval '3 day' and
      S_date < current_date

这适用于某些数据库。但数据库通常有自己的日期/时间函数,因此可能需要针对您的数据库定制语法。

在雪花中:

where S_date >= dateadd(day, -3, current_date) and
      S_date < current_date

推荐阅读