I want to group by ID, but each group of columns is displayed as a new horizontal set of columns.
I have a table with data like this
ββββββ¦ββββββββ¦βββββββββ
β ID β Phone β Type β
β βββββ¬ββββββββ¬βββββββββ£
β A β 111 β home β
β A β 222 β work β
β B β 333 β cell β
β B β 444 β school β
ββββββ©ββββββββ©βββββββββ
I want it to look like
ββββββ¦βββββββββ¦ββββββββ¦βββββββββ¦βββββββββ
β ID β Phone1 β Type1 β Phone2 β Type2 β
β βββββ¬βββββββββ¬ββββββββ¬βββββββββ¬βββββββββ£
β A β 111 β home β 222 β work β
β B β 333 β cell β 444 β school β
ββββββ©βββββββββ©ββββββββ©βββββββββ©βββββββββ
Ideally, I would find a solution that would handle an arbitrary number of repeating groups, but I could hardcode the number if I had to.
I can have up to 100,000 unique identifiers with 20 repeating sets of column groups, each of which can contain up to 5 separate columns.
PIVOT seems to help in this, but I cannot figure out how to do this.
EDIT: , , . , . . PIVOT, , ( -, !)
SQL Server 2012