SELECT * FROM table
WHERE From_date between '2013-01-03'
AND '2013-01-09'
如何将min(date1)和max(date2)用于上述查询
答案 0 :(得分:0)
使用变量存储表格的最短和最长日期
DECLARE @MinDate AS DATE
DECLARE @MaxDate AS DATE
SELECT @MinDate=MIN(From_date) , @MaxDate=MAX(From_date)
FROM table
然后在查询中使用它们
SELECT * FROM table
WHERE From_date between @MinDate AND @MaxDate