SQL 时间差计算

[复制链接]
查看11 | 回复5 | 2009-7-11 10:20:28 | 显示全部楼层 |阅读模式
同一个ID有可能存在多次登陆和登出用嵌套--> --> (Roy)生成测试数据 declare @T table([UserID] int,[OnP] nvarchar(3),[OnTime] Datetime)Insert @Tselect 1,N'on','2007-7-1 7:00' union allselect 1,N'off','2007-7-1 8:00' union allselect 2,N'on','2007-8-9 12:45' union allselect 3,N'on','2007-8-9 13:50' union allselect 2,N'off','2007-8-9 16:1...
回复

使用道具 举报

千问 | 2009-7-11 10:20:28 | 显示全部楼层
把OnP='off'的放到一个临时表中select * into #AA from A where OnP='off'把没有离开时间的用户加到临时表中insert into #AA (select * from A where UserID not in (select UserID from #AA))把临时表中的上面加的改一下登陆状态和时...
回复

使用道具 举报

千问 | 2009-7-11 10:20:28 | 显示全部楼层
用datediff函数就搞定了...
回复

使用道具 举报

千问 | 2009-7-11 10:20:28 | 显示全部楼层
有意思 我试试密切关注此问题...
回复

使用道具 举报

千问 | 2009-7-11 10:20:28 | 显示全部楼层
1.select a.userID,dateDiff(Hour,a.onTime,isnull(b.Ontime,getdate())) as onlineTime from A aleft joinA b on a.UserID=b.UserID and a.onp='On' and b.onp='OFF'2.select a.userID,s...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行