Simple SQLServer PIVOT/Transposed query, how to write?

后端 未结 2 1330
自闭症患者
自闭症患者 2021-01-17 02:36

I have a SELECT which is returning me data in the following form...

ID             Question             Answer
1              Any Good?            Yes
1              


        
2条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-17 03:03

    The pivot operation requires you to use some form of aggregate, however if you will only have one value Max() will grab the max (only) value for you

    Something Like this should work

    Select *
    from Table
    Pivot
    (
        Max(answer)
        For Question In ([Any Good?],[Happy?],[Good Staff?],[Return?])
    )
    AS P
    

提交回复
热议问题