How to convert rows into columns in SQL Server?

后端 未结 2 1450
你的背包
你的背包 2021-01-06 20:49

I have this table from fingerprint sensor and I need to show the result in one row

ID |  DateTime                | Flag
-------------------------------------         


        
2条回答
  •  没有蜡笔的小新
    2021-01-06 21:30

    Alternatively you could use PIVOT, which has been developed specifically to turn ROWS into COLUMNS.

    SELECT id
         , [I] as [IN-DateTime]
         , [O] as [OUT-DateTime]
    FROM Table t
    PIVOT (max(dateTime) for flag in ([I], [O])) as pvt;
    

提交回复
热议问题