求一存贮过程!

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是离线时间
...全文
119 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
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

34,873

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧