日期:2014-05-18 浏览次数:20770 次
--> 测试数据:[user] if object_id('[user]') is not null drop table [user] create table [user]([id] int,[name] varchar(4),[dept] varchar(2)) insert [user] select 1,'张三','IT' union all select 2,'李四','IT' union all select 3,'王五','IT' union all select 4,'小傅','HR' union all select 5,'小李','HR' union all select 6,'小红','HR' union all select 7,'小白','YW' --> 测试数据:[dept] if object_id('[dept]') is not null drop table [dept] create table [dept]([id] int,[starttime] datetime,[endtime] datetime,[dept] int) insert [dept] select 1,'2012-03-15 09:09:31.000','2012-03-15 20:09:31.050',1 union all select 2,'2012-03-15 08:09:31.050','2012-03-15 18:09:31.050',2 union all select 3,'2012-03-15 07:30:31.050','2012-03-15 20:09:31.050',4 select [user].[dept] as deptname,avg(cast(datediff(mi,[starttime], [endtime]) as decimal(10,2))/60)as avgtime from [user] inner join [dept] on [user].id=[dept].dept group by [user].[dept] deptname avgtime HR 12.650000 IT 10.500000 不大清楚你要干什么