In SQL I'm trying to split a column into multiple rows. This is how the data looks:
Person | Affiliation |
---|---|
Bob | AB, CR, DE |
Jane | AB |
This is how I'd like the results to look:
Person | Affiliation |
---|---|
Bob | AB |
Bob | CR |
Bob | DE |
Jane | AB |
I made a pretty unsophisticated attempt and am looking for feedback on alternate ways to accomplish this.
with
AB as (select AB.person, 'AB' affiliation from UP where up.affiliation like '%AB%'),
CR as (select CR.person, 'CR' affiliation from UP where up.affiliation like '%CR%'),
DE as (select DE.person, 'DE' affiliation from UP where up.affiliation like '%DE%')
select * from AB
union
select * from CR
union
select * from DE