开发者

Convert sql query

开发者 https://www.devze.com 2022-12-27 23:34 出处:网络
I have used this query in sql,pls convert this query to use for access database. Table structure is UserID,Username,LogDate,LogTime

I have used this query in sql,pls convert this query to use for access database.

Table structure is UserID,Username,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].U开发者_如何学CserId, 
    [OddRows].UserName, 
    [OddRows].LogDate, 
    [OddRows].LogTime, 
    [EvenRows].LogDate, 
    [EvenRows].LogTime  
FROM 
    [OddRows] LEFT JOIN [EvenRows] 
    ON [OddRows].RowId = [EvenRows].OddRowId 


AFAIK, Access doesn't support WITH. You'll have to use a temp table for TableWithRowId (assuming some equivalent of ROW_NUMBER() exists, which may not). The other tables, you can just convert to sub-selects.

0

精彩评论

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