• 全部
  • 基础类
  • 应用实例
  • 新技术前沿

求一存贮过程!

Hegemon 2008-04-03 03:59:42
表A
F_loginid F_logintime F_name F_Event(1=登录,0=离线)
0001 2008-04-03 14:40:04 aaa 1
0001 2008-04-03 14:40:59 aaa 0
0002 2008-04-03 14:42:09 aaa 1
0002 2008-04-03 14:44:13 aaa 0

要统计在线时长
统计结果如下:F_name F_logintime F_leveltime F_ontimes
aaa 2008-04-03 14:40:04 2008-04-03 14:40:59 00:00:55
aaa 2008-04-03 14:42:09 2008-04-03 14:44:13 00:02:04

F_Event=1 时F_logintime是登录时间
F_event=0 时F_logintime是离线时间
...全文
80 点赞 收藏 13
写回复
13 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
kaikai_kk 2008-04-04
[Quote=引用 9 楼 HEROWANG 的回复:]
引用 5 楼 utpcb 的回复:
他们写的简单了点吧! 如果楼住的里面登陆的同一个ID有多个登陆时间呢多个离线时间呢? 楼住你要自己慢慢看写一个完整的!

同意啊。如果一个用户登陆时,上一次的登陆信息还要不要保存呢?
[/Quote]


LZ现在的数据,好像就是同一用户aaa,登陆两次啊
回复
学习
回复
bote_china 2008-04-04

select
A.F_loginid,
A.F_logintime,
(select
min(F_logintime)
from A B
where B.F_Event=0 and B.F_loginid =A.F_loginid
and B.F_logintime>A.F_logintime)
AS F_LogoutTime,
F_name ,
F_event
from A
where f_event =1
order by F_loginid
回复
橘子香水 2008-04-03
select a.F_name,a.F_logintime,F_leveltime=b.F_logintime,
F_ontimes=b.F_logintime-a.F_logintime
from table a,table b
where a.F_Event=1 and b.F_Event=0 and
a.F_loginid=b.F_loginid
回复
[Quote=引用 5 楼 utpcb 的回复:]
他们写的简单了点吧! 如果楼住的里面登陆的同一个ID有多个登陆时间呢多个离线时间呢? 楼住你要自己慢慢看写一个完整的!
[/Quote]
同意啊。如果一个用户登陆时,上一次的登陆信息还要不要保存呢?
回复
sweetweiwei 2008-04-03
create procedure dbo.getA
as
select F_name,
F_logintime,
F_leveltime,
F_ontimes
from (select F_loginid,
F_name,
min(F_logintime) as F_logintime,
max(F_logintime) as F_leveltime,
max(F_logintime) - min(F_logintime) as F_ontimes
from A
group by F_loginid,F_name) t
go
回复
sweetweiwei 2008-04-03
create procedure dbo.getA
as
select F_name,
F_logintime,
F_leveltime,
F_ontimes
from (select F_loginid,
F_name,
min(F_logintime) as F_logintime,
max(F_logintime) as F_leveltime,
max(F_logintime) - min(F_logintime) as F_ontimes
from A
group by F_loginid,F_name) t
go
回复
pt1314917 2008-04-03


declare @t table(F_loginid varchar(10),F_logintime datetime,F_name varchar(10),F_Event int)
insert into @t select '0001','2008-04-03 14:40:04','aaa',1
insert into @t select '0001','2008-04-03 14:40:59','aaa',0
insert into @t select '0002','2008-04-03 14:42:09','aaa',1
insert into @t select '0002','2008-04-03 14:44:13','aaa',0


select a.f_name,a.F_logintime,b.F_logintime,
F_ontimes=convert(varchar(10),b.F_logintime-a.F_logintime,108)
from @t a,@t b
where a.f_name=b.f_name and a.F_loginid=b.F_loginid and b.f_event=0 and a.f_event=1
回复
utpcb 2008-04-03
他们写的简单了点吧! 如果楼住的里面登陆的同一个ID有多个登陆时间呢多个离线时间呢? 楼住你要自己慢慢看写一个完整的!
回复
-狙击手- 2008-04-03
select f_loginid,
f_name,
max(case when f_event = 1 then f_logintime else null end) as f_logintime,
max(case when f_event = 0 then f_logintime else null end) as F_leveltime ,
max(case when f_event = 1 then f_logintime else null end) -
max(case when f_event = 0 then f_logintime else null end) as f_ontimes ,
from ta
group by f_loginid,f_name
回复
liangCK 2008-04-03
[Quote=引用 1 楼 happyflystone 的回复:]
SQL codeselect f_loginid,
f_name,
max(case when f_event = 1 then f_logintime else null end) as f_logintime,
max(case when f_event = 0 then f_logintime else null end) as f_logintime,
max(case when f_event = 1 then f_logintime else null end) as f_logintime -
max(case when f_event = 0 then f_logintime else null end) as f_logintime,
from ta
group by f_login…
[/Quote]

BS盗版
回复
liangCK 2008-04-03
select f_name,
max(case when f_event=0 then f_logintime end) f_logintime,
max(case when f_event=1 then f_logintime end) f_leveltime,
max(case when f_event=1 then f_logintime end)-max(case when f_event=0 then f_logintime end) f_ontimes
from tb
group by f_loginid,f_name
回复
-狙击手- 2008-04-03
select f_loginid,
f_name,
max(case when f_event = 1 then f_logintime else null end) as f_logintime,
max(case when f_event = 0 then f_logintime else null end) as f_logintime,
max(case when f_event = 1 then f_logintime else null end) as f_logintime -
max(case when f_event = 0 then f_logintime else null end) as f_logintime,
from ta
group by f_loginid,f_name
回复
相关推荐
发帖
MS-SQL Server
创建于2007-09-28

3.3w+

社区成员

MS-SQL Server相关内容讨论专区
申请成为版主
帖子事件
创建了帖子
2008-04-03 03:59
社区公告
暂无公告