Hope this can be to some help it is done in oracle so you might need to edit some...
with data(id1, id2, v1, v2, v3) as(
select 'P1', 'I1', 'A', 'B', 'C' from dual union all
select 'P1', 'I2', 'D', 'E', 'F' from dual union all
select 'P2', 'I1', 'A', 'B', 'D' from dual union all
select 'P3', 'I1', 'A', 'D', 'E' from dual union all
select 'P2', 'I2', 'B', 'D', 'E' from dual
),
alla as (
select * from data where v1='A' or v2='A' or v3 ='A'
),
second AS
(select 'B' var ,((select count(V1) from alla where v1='B')+ (select count(V2) from alla where v2='B')+ (select count(V3) from alla where v3='B')) occur from dual union all
select 'C' var ,((select count(V1) from alla where v1='C')+ (select count(V2) from alla where v2='C')+ (select count(V3) from alla where v3='C')) occur from dual union all
select 'D' var ,((select count(V1) from alla where v1='D')+ (select count(V2) from alla where v2='D')+ (select count(V3) from alla where v3='D')) occur from dual union all
select 'E' var ,((select count(V1) from alla where v1='E')+ (select count(V2) from alla where v2='E')+ (select count(V3) from alla where v3='E')) occur from dual
),
third as ( select distinct data.* from data
join alla on data.id1 != alla.id1 and data.id2 != alla.id2
order by data.id1)
--fourth
select 'B' var ,((select count(V1) from third where v1='B')+ (select count(V2) from third where v2='B')+ (select count(V3) from third where v3='B')) occur from dual union all
select 'C' var ,((select count(V1) from third where v1='C')+ (select count(V2) from third where v2='C')+ (select count(V3) from third where v3='C')) occur from dual union all
select 'D' var ,((select count(V1) from third where v1='D')+ (select count(V2) from third where v2='D')+ (select count(V3) from third where v3='D')) occur from dual union all
select 'E' var ,((select count(V1) from third where v1='E')+ (select count(V2) from third where v2='E')+ (select count(V3) from third where v3='E')) occur from dual