0

Excel 列中的表格:

UID ID      StartDate     Time                              Name        
1    1       1/1/2012    5:51:12                            testA       
2    2       2/2/2012    5:51:12                            testB       
3    1       1/1/2012   10:51:12                            testA       
4    2       2/2/2012   10:51:12                            testB   

结果表目标:

UID ID      StartDate   StartTme    EndDate     EndTime     Name
1    1       1/1/2012    5:51:12    1/1/2012    10:51:12    testA
3    2       2/2/2012    5:51:12    2/2/2012    10:51:12    testB

使用 SQL 查询并从 Excel 列读取如何通过匹配第二次出现的 ID 来获取记录(StartDate、Time),并将这些作为新列按日期按升序插入“结束日期”、“结束时间”?

4

1 回答 1

0

试试这个,看看它是否会起作用:

SELECT
    UID = A.UID,
    ID = A.ID,
    StartDate = A.StartDate,
    StartTime = A.[Time],
    EndDate = B.StartDate,
    EndTime = B.[Time],
    Name = A.[Name]
FROM
    ExcelTable A
    JOIN ExcelTable B ON A.Id = B.ID 
ORDER BY
    A.StartDate,
    A,[Time]        
于 2013-01-11T20:49:42.530 回答