SQL Server: Examples of PIVOTing String data

前端 未结 7 1274
忘掉有多难
忘掉有多难 2020-11-21 13:20

Trying to find some simple SQL Server PIVOT examples. Most of the examples that I have found involve counting or summing up numbers. I just want to pivot some string data.

7条回答
  •  爱一瞬间的悲伤
    2020-11-21 14:02

    If you specifically want to use the SQL Server PIVOT function, then this should work, assuming your two original columns are called act and cmd. (Not that pretty to look at though.)

    SELECT act AS 'Action', [View] as 'View', [Edit] as 'Edit'
    FROM (
        SELECT act, cmd FROM data
    ) AS src
    PIVOT (
        MAX(cmd) FOR cmd IN ([View], [Edit])
    ) AS pvt
    

提交回复
热议问题