日期:2014-05-18 浏览次数:20529 次
declare @i int,@a datetime,@b datetime set @a='2012-03-28 09:00:00' set @b='2012-03-28 09:50:00' set @i=datediff(mi,@a,@b)*1.0/25 select @i select dateadd(mi,number*@i,@a),dateadd(mi,(number+1)*@i,@a) from master..spt_values where type='p' and number<=25
------解决方案--------------------
关键是你不知道怎么等分吧,参考
declare @a datetime = '2012-03-01' declare @b datetime = '2012-03-02 01:00' declare @minute int = datediff(minute,@a,@b)/25; with cte as ( select group_id=datediff(minute,dt,@a)/@minute, * from tb where dt between @a and @b ) select * into #tmp from cte t where [key] in (select top 5 [key] from tb where group_id=t.group_id order by newid()) select max(val)-min(val), avg(max(val)-min(val))over() from #tmp group by group_id