SQL Query with Dynamic Columns Using Pivot

后端 未结 3 2093
遥遥无期
遥遥无期 2021-01-25 08:40

I know this topic is everywhere but I couldn\'t get it to work properly. It\'s probably something very simple.

Here is a sample of the data after a basic query:

3条回答
  •  忘了有多久
    2021-01-25 09:28

    From your query

    PIVOT
    (
        max(Model)
        FOR Site in ' + @cols + ')
    ) AS piv
    

    you should use the column Count in MAX() function and Model in FOR...IN section. this is because your new values will be the Count and your new columns will be from the values in Model

提交回复
热议问题