您好我正在尝试编写查询,但我不确定如何执行此操作。这是一个场景,我想带回在特定时间开始前30分钟和之后2小时插入数据库的记录。这是我的查询的样子;
SELECT Comment.AddDate,Event.StartTime
FROM Comment
JOIN Users on Users.USERS_ID = Comment.UserID
JOIN Event ON Users.USERS_ID = Event.UserID
WHERE EventID = 5630
现在从上面我需要在Event.StartTime前30分钟和2小时后输入Comment.AddDate的记录。我该怎么做呢?
答案 0 :(得分:3)
SELECT Comment.AddDate, Event.StartTime
FROM Comment
JOIN Users ON Users.USERS_ID = Comment.UserID
JOIN Event ON Users.USERS_ID = Event.UserID
WHERE EventID = 5630
AND Comment.AddDate BETWEEN DATEADD(minute, -30, Event.StartTime)
AND DATEADD(hour, 2, Event.StartTime)
位于here的文档。