about Time(续3)

tim_spac 2008-04-17 04:19:17
与前面几帖的内容不同,本帖仅是理论上的,未在实际应用中检验过。请各位指正,以免误人误事。
/* 关于log记录配对
* log 通常包括portid / sessionid, 该id通常会被重用,但同一时刻不会重复
* 一组记录通常包含两条:先入,后出
*/

declare @logdata table (
logid char(36) not null, -- 类似 portid / sessionid, 该id通常会被重用,但同一时刻系统中不会重复出现
logtype tinyint, -- 方向, 1: login|入, 0: logout|出
logtime datetime -- 时间点
)

declare @logI table (id int identity(1,1), logid char(36), logItime datetime)
insert into @logI
-- 各个有效的进入时间点
select logid, logItime=logtime from @logdata a where logtype = 1
and exists (
-- 本次退出的时间
select min(logtime)
from @logdata c
where c.logid=a.logid and c.logtype=0 and c.logtime>a.logtime
)
and not (
-- 本次退出的时间
(
select min(logtime)
from @logdata c
where c.logid=a.logid and c.logtype=0 and c.logtime>a.logtime
) >
-- 下次进入的时间
(
select min(logtime)
from @logdata b
where logid=a.logid and logtype=1 and b.logtime>a.logtime
)
)
order by logid, logItime

declare @logO table (id int identity(1,1), logid char(36), logOtime datetime)
insert into @logO
-- 各个有效的退出时间点
select logid, logOtime=logtime from @logdata a where logtype = 0
and exists (
-- 本次进入的时间
select max(logtime)
from @logdata c
where c.logid=a.logid and c.logtype=1 and c.logtime<a.logtime
)
and not (
-- 本次进入的时间
(
select max(logtime)
from @logdata c
where c.logid=a.logid and c.logtype=1 and c.logtime<a.logtime
) <
-- 上次退出的时间
(
select max(logtime)
from @logdata b
where logid=a.logid and logtype=1 and b.logtime>a.logtime
)
)
order by logid, logOtime

-- 配对:
select a.logid, loginTime = logItime, logoutTime = logOtime
from @logI a, @logO b
where a.id=b.id


关于时间专题最近不再推出新内容(江郎才尽了)。如有相关话题也请告知,我将继续采集、整理、归纳、总结、推荐...兼散分 :)
...全文
157 25 打赏 收藏 转发到动态 举报
写回复
用AI写文章
25 条回复
切换为时间正序
请发表友善的回复…
发表回复
-狙击手- 2008-04-18
  • 打赏
  • 举报
回复
看看
晓风残月0110 2008-04-18
  • 打赏
  • 举报
回复
很好很专业
昵称被占用了 2008-04-18
  • 打赏
  • 举报
回复
mark
utpcb 2008-04-18
  • 打赏
  • 举报
回复
up
tim_spac 2008-04-18
  • 打赏
  • 举报
回复
一个精简版本:
set nocount on
go
/* 关于log记录配对 * log 通常包括portid / sessionid, 该id通常会被重用,但同一时刻不会重复 * 一组记录通常包含两条:先入,后出 */
declare @logdata table (
logid int not null, -- 类似 portid / sessionid, 该id通常会被重用,但同一时刻系统中不会重复出现
logtype tinyint, -- 方向, 1: login|入, 0: logout|出
logtime datetime -- 时间点
)

insert @logdata
select 1, 1 ,'2008-4-3 11:23:41' union
select 1, 0 ,'2008-4-3 15:23:41' union
select 1, 0 ,'2008-4-4 10:23:47' union -- 应该抛弃的记录
select 1, 1 ,'2008-4-5 10:22:47' union -- 应该抛弃的记录
select 1, 1 ,'2008-4-5 10:25:47' union
select 1, 0 ,'2008-4-7 14:23:11'

select a.logid, a.logtime, b.logtime
from @logdata a
join @logdata b on a.logid=b.logid and a.logtype!=b.logtype and b.logtime>a.logtime
and not exists (select 1 from @logdata b0 where b0.logid=b.logid and b0.logtype=b.logtype
and b0.logtime>a.logtime and b0.logtime<b.logtime)
where a.logtype=1 -- logtype=1为开始标记
and not exists (select 1 from @logdata a0
where a0.logid=a.logid and a0.logtype=a.logtype and a0.logtime>a.logtime
and a0.logtime < b.logtime)
go
tim_spac 2008-04-18
  • 打赏
  • 举报
回复
加分了,等待优化方案...
tim_spac 2008-04-18
  • 打赏
  • 举报
回复
...

/** 关于时段统计
* 假设数据存储于表 cdr, 每条记录包括 bgnTime为该记录的开始时间, endTime为该记录的结束时间
*/
declare @bgnTime datetime, @endTime datetime
set @bgnTime = '2008-4-15 10:00:00.000'
set @endTime = '2008-4-15 10:59:59.997'

-- 指定时段内的记录数 -----------------------------------------------
-- 按开始时间计算
select count(1) from cdr where bgnTime>=@bgnTime and bgnTime<@endTime
-- 按结束时间计算
select count(1) from cdr where endTime>@bgnTime and endTime<=@endTime
-- 按时间相交计算
select count(1) from cdr where endTime>@bgnTime and bgnTime<@endTime
-- 指定时段内的累计时长
select datediff(second
,case when bgnTime>@bgnTime then bgnTime else @bgnTime end
,case when endTime<@endTime then endTime else @endTime end )
from cdr where endTime>@bgnTime and bgnTime<@endTime

-- 指定时段内的最大并发 -----------------------------------------------
-- 各个时间点的并发数
select top 1 * from (
select timepoint, cnt = (select count(1) from cdr b where bgnTime<=timepoint and endTime>timepoint)
from (select distinct timepoint=bgnTime from cdr where bgnTime<@endTime and endTime>@bgnTime) as a
) as a order by cnt desc

-- 时间连续性分组 -----------------------------------------------
declare @tbgn table (id int identity(1,1), bgnTime datetime)
-- 该表每一数据的前一刻没有任何使用记录
insert into @tbgn select distinct bgnTime from cdr a
where not exists ( select 1 from cdr b where b.bgnTime<a.bgnTime and b.endTime>=a.bgnTime)
order by bgnTime

declare @tend table (id int identity(1,1), endTime datetime)
-- 该表每一数据的后一刻没有任何使用记录
insert into @tend select distinct endTime from cdr a
where not exists ( select 1 from cdr b where b.bgnTime<=a.endTime and b.endTime>a.endTime)
order by endTime

-- 分组整合
select a.id, bgnTime, endTime from @tbgn a, @tend b where a.id=b.id
go

/** 匹配login-logout.
* log 通常包括portid / sessionid, 该id通常会被重用,但同一时刻不会重复
* 一组记录通常包含两条:先入,后出
* 思路:针对每个id的进入时间统计, 过滤出有效的进入记录;并查出该时间点的有效退出记录
*/
-- 数据表
create table logdata (
logid int not null, -- 类似 portid / sessionid, 该id通常会被重用,但同一时刻系统中不会重复出现
logtype tinyint not null, -- 方向, 1: login|入, 0: logout|出
logtime datetime not null -- 时间点
)
go
-- 建立测试数据
insert logdata
select 1, 1, '2008-4-3 11:23:41' union all
select 1, 0, '2008-4-3 15:23:41' union all
select 1, 0, '2008-4-4 10:23:47' union all -- 因为缺失相匹配的进入记录,而应该抛弃的退出记录
select 1, 1, '2008-4-5 10:22:47' union all -- 因为缺失相匹配的退出记录,而应该抛弃的进入记录
select 1, 1, '2008-4-5 10:25:47' union all
select 1, 0, '2008-4-7 14:23:11' union all
select 1, 1, '2008-8-3 11:23:42' union all
select 1, 0, '2008-8-3 17:23:42' union all
select 1, 1, '2008-8-5 11:23:42' union all
select 1, 1, '2008-8-6 11:23:42' union all
select 1, 0, '2008-8-7 17:23:42' union all
select 1, 0, '2008-8-8 17:23:42' union all
select 2, 1, '2008-4-3 11:23:42' union all -- 另一个id的数据
select 2, 0, '2008-4-3 17:23:42' union all
select 2, 1, '2008-4-5 11:23:42' union all
select 2, 1, '2008-4-5 11:23:42' union all -- 重复记录,应抛弃
select 2, 0, '2008-4-5 17:23:42' union all
select 2, 0, '2008-4-5 17:23:42' -- 重复记录,应抛弃
go
create clustered index idx_log_id on logdata(logtype,logid,logtime)
go
-- * 感谢 算法设计者: do熊 * --
select
logid
,loginTime -- 通过 max(logtime) .. group by nCount 剔除无logout匹配的进入记录
= max(logtime)
,logoutTime -- 直接找到该进入时刻之后,最早一条退出记录的时间;该方法抛弃了无login匹配的退出记录
= (select min(logtime) from logdata where logtype=0 and logid=I.logid and logtime>max(I.logtime))
from
(
select
logid
,logtime
,nCount = -- 该时间点之前的退出记录个数
(select count(1) from logdata where logtype=0 and logid=L.logid and logtime<L.logtime)
from logdata L where logtype=1 -- 进入记录
) I
group by logid , nCount
order by logid
go
drop table logdata
go
tim_spac 2008-04-18
  • 打赏
  • 举报
回复
关于时间议题的小结
/** 关于 convert datetime 日期样式参数的效果
*/
set nocount on declare @dt datetime set @dt = getdate()

print 'convert(varchar,@dt, 0) : '+ convert(varchar,@dt,0)
print 'convert(varchar,@dt, 1) : '+ convert(varchar,@dt,1)
print 'convert(varchar,@dt, 2) : '+ convert(varchar,@dt,2)
print 'convert(varchar,@dt, 3) : '+ convert(varchar,@dt,3)
print 'convert(varchar,@dt, 4) : '+ convert(varchar,@dt,4)
print 'convert(varchar,@dt, 5) : '+ convert(varchar,@dt,5)
print 'convert(varchar,@dt, 6) : '+ convert(varchar,@dt,6)
print 'convert(varchar,@dt, 7) : '+ convert(varchar,@dt,7)
print 'convert(varchar,@dt, 8) : '+ convert(varchar,@dt,8)
print 'convert(varchar,@dt, 9) : '+ convert(varchar,@dt,9)
print 'convert(varchar,@dt,10) : '+ convert(varchar,@dt,10)
print 'convert(varchar,@dt,11) : '+ convert(varchar,@dt,11)
print 'convert(varchar,@dt,12) : '+ convert(varchar,@dt,12)
print 'convert(varchar,@dt,13) : '+ convert(varchar,@dt,13)
print 'convert(varchar,@dt,14) : '+ convert(varchar,@dt,14)
print '15 ~ 19 为无效样式号'
print 'convert(varchar,@dt,20) : '+ convert(varchar,@dt,20)
print 'convert(varchar,@dt,21) : '+ convert(varchar,@dt,21)
print 'convert(varchar,@dt,22) : '+ convert(varchar,@dt,22)
print 'convert(varchar,@dt,23) : '+ convert(varchar,@dt,23)
print 'convert(varchar,@dt,24) : '+ convert(varchar,@dt,24)
print 'convert(varchar,@dt,25) : '+ convert(varchar,@dt,25)
print '26 ~ 29 为无效样式号'
print 'convert(varchar,@dt,100) : '+ convert(varchar,@dt,100)
print 'convert(varchar,@dt,101) : '+ convert(varchar,@dt,101)
print 'convert(varchar,@dt,102) : '+ convert(varchar,@dt,102)
print 'convert(varchar,@dt,103) : '+ convert(varchar,@dt,103)
print 'convert(varchar,@dt,104) : '+ convert(varchar,@dt,104)
print 'convert(varchar,@dt,105) : '+ convert(varchar,@dt,105)
print 'convert(varchar,@dt,106) : '+ convert(varchar,@dt,106)
print 'convert(varchar,@dt,107) : '+ convert(varchar,@dt,107)
print 'convert(varchar,@dt,108) : '+ convert(varchar,@dt,108)
print 'convert(varchar,@dt,109) : '+ convert(varchar,@dt,109)
print 'convert(varchar,@dt,110) : '+ convert(varchar,@dt,110)
print 'convert(varchar,@dt,111) : '+ convert(varchar,@dt,111)
print 'convert(varchar,@dt,112) : '+ convert(varchar,@dt,112)
print 'convert(varchar,@dt,113) : '+ convert(varchar,@dt,113)
print 'convert(varchar,@dt,114) : '+ convert(varchar,@dt,114)
print '115 ~ 119 为无效样式号'
print 'convert(varchar,@dt,120) : '+ convert(varchar,@dt,120)
print 'convert(varchar,@dt,121) : '+ convert(varchar,@dt,121)
print '122 ~ 129 为无效样式号'

-- convert(varchar,@dt, 0) : 04 14 2008 3:57PM
-- convert(varchar,@dt, 1) : 04/14/08
-- convert(varchar,@dt, 2) : 08.04.14
-- convert(varchar,@dt, 3) : 14/04/08
-- convert(varchar,@dt, 4) : 14.04.08
-- convert(varchar,@dt, 5) : 14-04-08
-- convert(varchar,@dt, 6) : 14 04 08
-- convert(varchar,@dt, 7) : 04 14, 08
-- convert(varchar,@dt, 8) : 15:57:16
-- convert(varchar,@dt, 9) : 04 14 2008 3:57:16:483PM
-- convert(varchar,@dt,10) : 04-14-08
-- convert(varchar,@dt,11) : 08/04/14
-- convert(varchar,@dt,12) : 080414
-- convert(varchar,@dt,13) : 14 04 2008 15:57:16:483
-- convert(varchar,@dt,14) : 15:57:16:483
-- 15 ~ 19 为无效样式号
-- convert(varchar,@dt,20) : 2008-04-14 15:57:16
-- convert(varchar,@dt,21) : 2008-04-14 15:57:16.483
-- convert(varchar,@dt,22) : 04/14/08 3:57:16 PM
-- convert(varchar,@dt,23) : 2008-04-14
-- convert(varchar,@dt,24) : 15:57:16
-- convert(varchar,@dt,25) : 2008-04-14 15:57:16.483
-- 26 ~ 29 为无效样式号
-- convert(varchar,@dt,100) : 04 14 2008 3:57PM
-- convert(varchar,@dt,101) : 04/14/2008
-- convert(varchar,@dt,102) : 2008.04.14
-- convert(varchar,@dt,103) : 14/04/2008
-- convert(varchar,@dt,104) : 14.04.2008
-- convert(varchar,@dt,105) : 14-04-2008
-- convert(varchar,@dt,106) : 14 04 2008
-- convert(varchar,@dt,107) : 04 14, 2008
-- convert(varchar,@dt,108) : 15:57:16
-- convert(varchar,@dt,109) : 04 14 2008 3:57:16:483PM
-- convert(varchar,@dt,110) : 04-14-2008
-- convert(varchar,@dt,111) : 2008/04/14
-- convert(varchar,@dt,112) : 20080414
-- convert(varchar,@dt,113) : 14 04 2008 15:57:16:483
-- convert(varchar,@dt,114) : 15:57:16:483
-- 115 ~ 119 为无效样式号
-- convert(varchar,@dt,120) : 2008-04-14 15:57:16
-- convert(varchar,@dt,121) : 2008-04-14 15:57:16.483
-- 122 ~ 129 为无效样式号
go

/** 关于时间区间
*/
set nocount on declare @dt datetime set @dt = getdate()
declare @dt1 datetime, @dt2 datetime

set @dt1 = dateadd(hour,datediff(hour,0,@dt),0)
set @dt2 = dateadd(ms,-3, dateadd(hour,datediff(hour,0,@dt)+1,0) )
print '当时: ' + convert(varchar,@dt1,121) + ' ~ ' + convert(varchar,@dt2,121)

set @dt1 = dateadd(day,datediff(day,0,@dt),0)
set @dt2 = dateadd(ms,-3, dateadd(day,datediff(day,0,@dt)+1,0) )
print '当日: ' + convert(varchar,@dt1,121) + ' ~ ' + convert(varchar,@dt2,121)

set @dt1 = dateadd(week,datediff(week,0,@dt),0)
set @dt2 = dateadd(ms,-3, dateadd(week,datediff(week,0,@dt)+1,0) )
print '当周: ' + convert(varchar,@dt1,121) + ' ~ ' + convert(varchar,@dt2,121)

set @dt1 = dateadd(month,datediff(month,0,@dt),0)
set @dt2 = dateadd(ms,-3, dateadd(month,datediff(month,0,@dt)+1,0) )
print '当月: ' + convert(varchar,@dt1,121) + ' ~ ' + convert(varchar,@dt2,121)

set @dt1 = dateadd(quarter,datediff(quarter,0,@dt),0)
set @dt2 = dateadd(ms,-3, dateadd(quarter,datediff(quarter,0,@dt)+1,0) )
print '当季: ' + convert(varchar,@dt1,121) + ' ~ ' + convert(varchar,@dt2,121)

set @dt1 = dateadd(year,datediff(year,0,@dt),0)
set @dt2 = dateadd(ms,-3, dateadd(year,datediff(year,0,@dt)+1,0) )
print '当年: ' + convert(varchar,@dt1,121) + ' ~ ' + convert(varchar,@dt2,121)
go
-- 当时: 2008-04-14 16:00:00.000 ~ 2008-04-14 16:59:59.997
-- 当日: 2008-04-14 00:00:00.000 ~ 2008-04-14 23:59:59.997
-- 当周: 2008-04-14 00:00:00.000 ~ 2008-04-20 23:59:59.997
-- 当月: 2008-04-01 00:00:00.000 ~ 2008-04-30 23:59:59.997
-- 当季: 2008-04-01 00:00:00.000 ~ 2008-06-30 23:59:59.997
-- 当年: 2008-01-01 00:00:00.000 ~ 2008-12-31 23:59:59.997
...
tim_spac 2008-04-18
  • 打赏
  • 举报
回复
而且增强容错
tim_spac 2008-04-18
  • 打赏
  • 举报
回复
太棒了。又少一次扫描! thanks bear!
dobear_0922 2008-04-18
  • 打赏
  • 举报
回复
Ctrl+L显示:
建表耗时----15%
查询耗时----do熊 31%, Time Space 55%
kk19840210 2008-04-18
  • 打赏
  • 举报
回复
接分 学习
zccmy22 2008-04-18
  • 打赏
  • 举报
回复
学习关注中。大家都多发表点意见,让小兵我学学。
青锋-SS 2008-04-18
  • 打赏
  • 举报
回复
[Quote=引用 17 楼 xiaoku 的回复:]
谢谢...学习...接分
[/Quote]
xiaoku 2008-04-18
  • 打赏
  • 举报
回复
谢谢...学习.
dobear_0922 2008-04-18
  • 打赏
  • 举报
回复
贴个效率比Time Space高点儿的,,,
declare @logdata table ( 
logid int not null, -- 类似 portid / sessionid, 该id通常会被重用,但同一时刻系统中不会重复出现
logtype tinyint, -- 方向, 1: login|入, 0: logout|出
logtime datetime -- 时间点
)

insert @logdata
select 1, 1 ,'2008-4-3 11:23:41' union all
select 1, 0 ,'2008-4-3 15:23:41' union all
select 1, 0 ,'2008-4-4 10:23:47' union all -- 应该抛弃的记录
select 1, 1 ,'2008-4-5 10:22:47' union all -- 应该抛弃的记录
select 1, 1 ,'2008-4-5 10:25:47' union all
select 1, 0 ,'2008-4-7 14:23:11'
union all select 1, 1, '2008-8-3 11:23:42'
union all select 1, 0, '2008-8-3 17:23:42'
union all select 1, 1, '2008-8-5 11:23:42'
union all select 1, 1, '2008-8-6 11:23:42'
union all select 1, 0, '2008-8-7 17:23:42'
union all select 1, 0, '2008-8-8 17:23:42'
--union all select 2, 1, '2008-4-3 11:23:42' --经测试,楼主的代码不能去掉重复的,do熊的可以。
--union all select 2, 0, '2008-4-3 17:23:42'
--union all select 2, 1, '2008-4-5 11:23:42'
--union all select 2, 1, '2008-4-5 11:23:42'
--union all select 2, 0, '2008-4-5 17:23:42'
--union all select 2, 0, '2008-4-5 17:23:42'

--do熊
select logid, loginTime=max(logtime)
, logoutTime=(select min(logtime) from @logdata where logtype=0 and logid=I.logid and logtime>max(I.logtime))
from
(
select logid, logtime, nCount=(select count(1) from @logdata where logtype=0 and logid=L.logid and logtime<L.logtime)
from @logdata L where logtype=1
) I
group by logid, nCount
order by logid

--Time Space
select a.logid, a.logtime, b.logtime
from @logdata a
join @logdata b on a.logid=b.logid and a.logtype!=b.logtype and b.logtime>a.logtime
and not exists (select 1 from @logdata b0 where b0.logid=b.logid and b0.logtype=b.logtype
and b0.logtime>a.logtime and b0.logtime<b.logtime)
where a.logtype=1 -- logtype=1为开始标记
and not exists (select 1 from @logdata a0
where a0.logid=a.logid and a0.logtype=a.logtype and a0.logtime>a.logtime
and a0.logtime < b.logtime)
order by a.logid


/*
logid loginTime logoutTime
----------- ----------------------- -----------------------
1 2008-04-03 11:23:41.000 2008-04-03 15:23:41.000
1 2008-04-05 10:25:47.000 2008-04-07 14:23:11.000
1 2008-08-03 11:23:42.000 2008-08-03 17:23:42.000
1 2008-08-06 11:23:42.000 2008-08-07 17:23:42.000

(4 row(s) affected)

logid logtime logtime
----------- ----------------------- -----------------------
1 2008-04-03 11:23:41.000 2008-04-03 15:23:41.000
1 2008-04-05 10:25:47.000 2008-04-07 14:23:11.000
1 2008-08-03 11:23:42.000 2008-08-03 17:23:42.000
1 2008-08-06 11:23:42.000 2008-08-07 17:23:42.000

(4 row(s) affected)
*/
tim_spac 2008-04-17
  • 打赏
  • 举报
回复
没细考虑,仅按逻辑表达出来。一起来优化吧
dobear_0922 2008-04-17
  • 打赏
  • 举报
回复
and not exists ( select 1 where
-- 本次退出的时间
( select min(logtime) from @logdata c where c.logid=a.logid and c.logtype=0 and c.logtime>a.logtime )
>
-- 下次进入的时间
( select min(logtime) from @logdata b where logid=a.logid and logtype=1 and b.logtime>a.logtime )
)


-----------------
这个可以简化一下吧
dobear_0922 2008-04-17
  • 打赏
  • 举报
回复
看看
tim_spac 2008-04-17
  • 打赏
  • 举报
回复
set nocount on
go
/* 关于log记录配对 * log 通常包括portid / sessionid, 该id通常会被重用,但同一时刻不会重复 * 一组记录通常包含两条:先入,后出 */
declare @logdata table (
logid char(36) not null, -- 类似 portid / sessionid, 该id通常会被重用,但同一时刻系统中不会重复出现
logtype tinyint, -- 方向, 1: login|入, 0: logout|出
logtime datetime -- 时间点
)

insert @logdata
select 1, 1 ,'2008-4-3 11:23:41' union
select 1, 0 ,'2008-4-3 15:23:41' union
select 1, 0 ,'2008-4-4 10:23:47' union
select 1, 1 ,'2008-4-5 10:25:47' union
select 1, 0 ,'2008-4-7 14:23:11'


declare @logI table (id int identity(1,1), logid char(36), logItime datetime)
insert into @logI -- 各个有效的进入时间点
select logid, logItime=logtime from @logdata a
where logtype = 1
and exists (
-- 本次退出的时间
select 1 from @logdata c where c.logid=a.logid and c.logtype=0 and c.logtime>a.logtime )
and not exists ( select 1 where
-- 本次退出的时间
( select min(logtime) from @logdata c where c.logid=a.logid and c.logtype=0 and c.logtime>a.logtime )
>
-- 下次进入的时间
( select min(logtime) from @logdata b where logid=a.logid and logtype=1 and b.logtime>a.logtime )
)
order by logid, logItime

declare @logO table (id int identity(1,1), logid char(36), logOtime datetime)
insert into @logO -- 各个有效的退出时间点
select logid, logOtime=logtime from @logdata a
where logtype = 0
and exists (
-- 本次进入的时间
select 1 from @logdata c where c.logid=a.logid and c.logtype=1 and c.logtime<a.logtime )
and not exists ( select 1 where
-- 本次进入的时间
( select max(logtime) from @logdata c where c.logid=a.logid and c.logtype=1 and c.logtime<a.logtime )
<
-- 上次退出的时间
( select max(logtime) from @logdata b where logid=a.logid and logtype=0 and b.logtime<a.logtime )
)
order by logid, logOtime

-- 配对:
select a.logid, loginTime = logItime, logoutTime = logOtime from @logI a, @logO b where a.id=b.id
--
-- logid,loginTime,logoutTime
-- 1,2008-04-03 11:23:41,2008-04-03 15:23:41
-- 1,2008-04-05 10:25:47,2008-04-07 14:23:11
--


参考 <<时间差的问题>>实例并休整代码。
加载更多回复(5)

34,588

社区成员

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

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