日期:2014-05-18 浏览次数:20643 次
select bh,date, datediff(ms,date+' ' +max(time), date + ' ' + min(time))from tb group by bh,date
------解决方案--------------------
create table #tt (bh varchar(10),[date] varchar(20),[time] varchar(20))
insert into #tt
select '1','20070809','08:00:00'
union all
select '1','20070809','09:00:00'
union all
select '1','20070809','17:00:00'
union all
select '1','20070810','07:00:00'
union all
select '2','20070809','08:00:00'
union all
select '3','20070810','08:00:00'
select bh,[date],datediff(minute,min([time]),max([time])) '相差(分)' from #tt group by bh,[date] order by [date]