简体   繁体   English

Sql 查询不包括当前日期的数据

[英]Sql query for data excluding current date

Hi I want to select last 3 days data excluding Current date.嗨,我想 select 过去 3 天的数据,不包括当前日期。

I am trying something like below on Snowflake.我在雪花上尝试类似下面的东西。

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

But it is also including current date too.但它也包括当前日期。

Please help.请帮忙。

In Standard SQL, the syntax would be:在标准 SQL 中,语法为:

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

This works in some databases.这适用于某些数据库。 But databases typically have their own date/time functions, so the syntax likely needs to be customized to your database.但数据库通常有自己的日期/时间函数,因此可能需要针对您的数据库定制语法。

In Snowflake:在雪花中:

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

You did not say what platform you are running on.你没有说你在什么平台上运行。 On sql server this will work在 sql 服务器上,这将起作用

SELECT *
FROM Table
WHERE S_date BETWEEN DATEADD(DAY, -3, current_date) AND DATEADD(DAY,-1, current_date)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM