I have several columns and making pivot. I want to have multiple non-pivot columns and to make pivot using the last one. In the original specification here it is shown that you can have only one non-pivot column.
SELECT <non-pivoted column>,
[first pivoted column] AS <column name>,
[second pivoted column] AS <column name>,
...
[last pivoted column] AS <column name>
FROM
(<SELECT query that produces the data>)
AS <alias for the source query>
PIVOT
(
<aggregation function>(<column being aggregated>)
FOR
[<column that contains the values that will become column headers>]
IN ( [first pivoted column], [second pivoted column],
... [last pivoted column])
) AS <alias for the pivot table>
<optional ORDER BY clause>;
Is there a way to have more non-pivot columns, because it is pivoting my data using all columns after the first one.
Yes. Just add them.
eg