2010-04-25 110 views
1

繼數據和使用的MS Access使用VB6MS Access查詢時間

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 

需要輸出如下6列: -

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

這不會是快:

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