The simplest method is to combine these into a single column using listagg()
:
select OfficeLocation,
listagg(personid, ',') within group (order by personid) as personids
from t
group by OfficeLocation;
I do not recommend putting the values in separate columns for several reasons. First, you don't know how many columns you will need. Second, you can do this using dynamic SQL, but you cannot create a view for the result. Third, the same person could -- in theory -- appear in multiple rows, but the person would likely be in different columns.
EDIT:
If you want exactly six columns, you can use conditional aggregation:
select OfficeLocation,
max(case when seqnum = 1 then PersonId) as PersonId_1,
max(case when seqnum = 2 then PersonId) as PersonId_2,
max(case when seqnum = 3 then PersonId) as PersonId_3,
max(case when seqnum = 4 then PersonId) as PersonId_4,
max(case when seqnum = 5 then PersonId) as PersonId_5,
max(case when seqnum = 6 then PersonId) as PersonId_6
from (select t.*,
row_number() over (partition by OfficeLocation order by personid) as seqnum
from t
) t
group by OfficeLocation;
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…