MS Access query for time

佐手、 提交于 2020-01-05 05:32:09

问题


Following data and using MS Access with VB6

UserID  UserName  LogTime LogDate  

1       S         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  

回答1:


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


来源:https://stackoverflow.com/questions/2708525/ms-access-query-for-time

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!