我想知道怎么做不.在其他表中使用getdate()和现有日期的天数,其中该表包含多个记录,即我想知道5天前或10天后或15天后发布的作业.我写过这样的查询
declare @q1 datetime;
select cdate from jobposting where cdate like (select cdate)
select datediff ( dd, q1, getdate())
Run Code Online (Sandbox Code Playgroud)
其中q1必须存储jobposting表中的所有日期,但我无法得到正确的答案.
或者我也尝试过
select datediff ( dd, select cdate from jobposting, getdate())
Run Code Online (Sandbox Code Playgroud)
在提前感谢你.
如果我正确理解您的问题,有两种常用方法可以达到您的要求:
首先,使用datediff()作为Kim的建议.
另一个是计算出5天前的日期,然后将表中的日期与它进行比较(如果列被索引,则应该比DateDiff快):
declare @cutoff datetime;
set @cutoff = dateadd(day, -5, getdate());
select * from jobposting where cdate >= @cutoff;
Run Code Online (Sandbox Code Playgroud)