2010-04-26 160 views
-1

我已在sql中使用此查詢,請轉換此查詢以用於訪問數據庫。轉換sql查詢

表結構是用戶名,用戶名,LOGDATE,LOGTIME

WITH 
    [TableWithRowId] as 
    (SELECT ROW_NUMBER() OVER(ORDER BY UserId,LogDate,LogTime) RowId, * FROM @YourTable), 
    [OddRows] as 
    (SELECT * FROM [TableWithRowId] WHERE rowid % 2 = 1), 
    [EvenRows] as 
    (SELECT *, RowId-1 As OddRowId FROM [TableWithRowId] WHERE rowid % 2 = 0) 
SELECT 
    [OddRows].UserId, 
    [OddRows].UserName, 
    [OddRows].LogDate, 
    [OddRows].LogTime, 
    [EvenRows].LogDate, 
    [EvenRows].LogTime 
FROM 
    [OddRows] LEFT JOIN [EvenRows] 
    ON [OddRows].RowId = [EvenRows].OddRowId 
+0

@nisha這是關於http://stackoverflow.com/questions/2708525/ms-access-query-for-time? – Fionnuala 2010-04-26 10:39:20

+0

是的,先生,它與它有關 – nisha 2010-04-26 10:45:02

回答

1

據我所知,Access不支持WITH。您必須使用TableWithRowId的臨時表(假設存在一些等效的ROW_NUMBER(),這可能不會)。其他表格,您可以轉換爲子選擇。