sql 查询以获取超过 3 周的内容

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1591888/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 04:04:39  来源:igfitidea点击:

sql query to get content older than 3 weeks

sqlsql-servertsql

提问by mrblah

My content table looks like (contentID, title, created). I need to get all content that was created more than 3 weeks ago.

我的内容表看起来像 (contentID, title, created)。我需要获取超过 3 周前创建的所有内容。

Sql server database, created is datetime type.

Sql server 数据库,创建的是日期时间类型。

回答by Rob Farley

How about:

怎么样:

select contentID, title, created 
from content
where created < dateadd(week,-3,getdate());

This sticks closer to the question. 21 days is fine, obviously means the same, but I find that it's good to use the terminology used in the question.

这更接近问题。21 天很好,显然意思相同,但我发现使用问题中使用的术语很好。

For example... a while back I was asked to survey an average of 1 in 50 visitors to a site. I described this as a proportion of 0.02, and the client wasn't happy. I pointed out to the client that they're the same, but I learned my lesson, and now if I change the way that something is described, I make sure I comment to that effect, and preferably don't change it in the first place. If the client wants 3 weeks, do it as 3 weeks, not 21 days.

例如... 不久前,我被要求对网站的平均 50 名访问者中的 1 人进行调查。我将其描述为 0.02 的比例,客户并不满意。我向客户指出它们是相同的,但我吸取了教训,现在如果我改变描述某事的方式,我确保我对此发表评论,并且最好不要在第一次改变它地方。如果客户想要 3 周,就按 3 周来做,而不是 21 天。

回答by J.Hendrix

in MS SQl 2000/2005 you can do this

在 MS SQl 2000/2005 中你可以这样做

Select
   contactID,
   title,
   created
from
   content
where
   created < getdate()-21

回答by Himadri

Try this:

尝试这个:

select contentID, title, created from content
where created < dateadd(day,-21,getdate())