SQL Server: Examples of PIVOTing String data

前端 未结 7 1280
忘掉有多难
忘掉有多难 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 13:41

    Well, for your sample and any with a limited number of unique columns, this should do it.

    select 
        distinct a,
        (select distinct t2.b  from t t2  where t1.a=t2.a and t2.b='VIEW'),
        (select distinct t2.b from t t2  where t1.a=t2.a and t2.b='EDIT')
    from t t1
    

提交回复
热议问题