开发者

MS Access query for time

开发者 https://www.devze.com 2022-12-28 06:40 出处:网络
Following data and using MS Access with VB6 UserIDUserNameLogTime LogDate 1S开发者_如何学JAVA9:0021/5/2010

Following data and using MS Access with VB6

UserID  UserName  LogTime LogDate  

1       S      开发者_如何学JAVA   9:00    21/5/2010  
1       S         10:00   21/5/2010  
1       S         11:00   21/5/2010  
1       S         12:00   21/5/2010  
1       S         14:00   21/5/2010 
1       S         17:00   21/5/2010  

Need Output as in below 6 columns:-

1     S      21/5/2010 9:00  21/5/2010 10:00  
1     S      21/5/2010 11:00 21/5/2010 12:00  
1     S      21/5/2010 14:00 21/5/2010 17:00  


This is not going to be fast:

SELECT x.UserID, x.UserName, y.LogTime, x.LogTime, y.LogDate
FROM (
      SELECT Test.UserID, Test.UserName, 
             Test.LogTime, Test.LogDate, 
             (SELECT Count(*) FROM Test t WHERE t.LogTime<=Test.LogTime) AS c
      FROM Test)  AS x 
INNER JOIN (
      SELECT Test.UserID, Test.UserName, 
             Test.LogTime, Test.LogDate, 
             (SELECT Count(*) FROM Test t WHERE t.LogTime<=Test.LogTime) AS c, 
             c+1 as k
      FROM Test)  AS y 
ON x.c = y.k
WHERE x.c Mod 2=0
0

精彩评论

暂无评论...
验证码 换一张
取 消