SQL Server row and column transformation hidden group
Pivot has a hidden group group, except for pivot column and value column, and other columns as groupings
Example:
IF not EXISTS (SELECT * from sys.tables where name = ' Pivot_test ')
CREATE TABLE Pivot_test
(
ID1 int,
Id2 int,
Pivot_column varchar (50),
Value char (50)
)
INSERT into pivot_test values (A, ' A ', ' A_v '), (with the ' B ', ' B_v '), (with the ' C ', ' C_v '), (with the ' D ', ' D_v ')
Row and column conversions
SELECT * from Pivot_test Pivot (MAX (value) to Pivot_column in (a,b,c,d)) TEM
Update A of the ID2 value of 2, again row and column conversion, found that two lines, proving that id2 affect the group
Update pivot_test Set id2 = 2 WHERE pivot_column = ' A '
SELECT * from Pivot_test Pivot (MAX (value) to Pivot_column in (a,b,c,d)) TEM
Update A's ID1 value to 2,id2 update to the old value 1, see the row and column conversion results again, find the result is still two lines, prove that ID1 is also in the group
Update pivot_test Set id2 = 1 WHERE pivot_column = ' A '
Update pivot_test Set id1 = 2 WHERE pivot_column = ' A '
SELECT * from Pivot_test Pivot (MAX (value) to Pivot_column in (a,b,c,d)) TEM
The above proves that pivot is grouped with all other columns except pivot column and value
SQL Server Pivot hidden Group