日期:2014-05-17 浏览次数:20478 次
create table tb(users nvarchar(20),operate nvarchar(20),dtime datetime)
insert into tb select 'LiMing','Login','2010/10/24 8:03'
insert into tb select 'WangYi','Login','2010/10/24 8:14'
insert into tb select 'WangYi','Logout','2010/10/24 16:14'
insert into tb select 'LiMing','Logout','2010/10/24 16:44'
go
select a.users,datediff(mi,b.dtime,a.dtime)
from tb a inner join tb b on a.users=b.users
where a.operate='Logout' and b.operate='Login'
/*
users
-------------------- -----------
WangYi 480
LiMing 521
(2 行受影响)
*/
go
drop table tb