我正在尝试使用查询和表格查找用户开始日期后2周内的事件开启日期。
我有一张这样的表
ID | StartDate | OpenedDate
---|-------------------------|---------------------
1 | 2014-01-02 05:44:47.000 | 2014-01-14 00:00:00.000
2 | 2011-01-02 13:35:01.000 | 2012-07-09 00:00:00.000
3 | 2011-01-02 13:35:01.000 | 2011-01-10 00:00:00.000
4 | 2011-01-02 13:35:01.000 | 2012-07-09 00:00:00.000
5 | 2011-01-02 13:35:01.000 | 2012-07-09 00:00:00.000
我只想要第1行和第3行,因为StartDate在opendate的2周内
答案 0 :(得分:0)
试试这个:
SELECT
ID,
StartDate,
OpenedDate
FROM
mytable
WHERE
OpenedDate >= DATEADD(d, -14, StartDate)
答案 1 :(得分:0)
SELECT
ID,
StartDate,
OpenedDate
FROM
mytable
WHERE
datediff(wk,getdate(),startdate)<=2