您好我有一个Showings表(节目),我希望能够从今天开始选择上一个和下一个“Show”(getdate()))
表结构有这个; SHOW_ID,ShowNumber,Name,EventTime
SELECT SHOW_ID, ShowNumber, Name, EventTime
FROM Event Where EventID = @EventID
多数民众赞成在哪里被困,我该怎么做呢,提前谢谢。
答案 0 :(得分:1)
-- Get the next showing of the event that will occur directly after the current datetime
SELECT TOP 1 SHOW_ID, ShowNumber, Name, EventTime
FROM Event WHERE EventTime > GetDate() AND EventId = @EventId
ORDER BY EventTime asc
-- Optionally, if you wanted to get the above and below results in a single SELECT,
-- you could use a UNION here. i.e.:
-- UNION
-- Get the first event that occurred directly before the current datetime
SELECT TOP 1 SHOW_ID, ShowNumber, Name, EventTime
FROM Event WHERE EventTime < GetDate() AND EventId = @EventId
ORDER BY EventTime desc