从日期范围开始和结束日期

时间:2014-07-03 18:22:42

标签: sql-server

我有以下日期范围:

06/28/2014
06/29/2014
06/30/2014
07/01/2014
07/02/2014

我想找到给定日期范围内的最小和最大日期。在这种情况下,分别为06/28/201407/02/2014

1 个答案:

答案 0 :(得分:2)

以下是答案,但下次尝试自己找到这个简单的答案:

DECLARE @datesTable TABLE (Dates DATE)


INSERT INTO @datesTable SELECT '06/28/2014'
INSERT INTO @datesTable SELECT '06/29/2014'
INSERT INTO @datesTable SELECT '06/30/2014'
INSERT INTO @datesTable SELECT '07/01/2014'
INSERT INTO @datesTable SELECT '07/02/2014'


SELECT MAX(Dates) AS MaxDate, MIN(Dates) AS MinDate
FROM @datesTable