日期:2014-05-18 浏览次数:20592 次
startDate endDate 2012-1-1 2012-1-1 ... ... 2012-1-15 2012-1-16
create table tb ( startdate datetime, enddate datetime ) insert into tb select '2012-1-1','2012-1-1' union all select '2012-1-4','2012-1-6' union all select '2012-1-15','2012-1-16' select MIN (startdate),MAX (enddate) from tb
------解决方案--------------------
create table mpt (startDate date, endDate date) insert into mpt select '2012-1-1', '2012-1-1' union all select '2012-1-15', '2012-1-16' with t as (select row_number() over(order by (select 0)) rn, startDate,endDate from mpt) select (select startDate from t where rn=1) startDate, (select top 1 endDate from t order by rn desc) endDate startDate endDate ---------- ---------- 2012-01-01 2012-01-16 (1 row(s) affected)