This is a naive solution but may help to get to a more dynamic way of approaching the problem:
drop table if exists #test;
drop table if exists #result;
create table #test (
[ID] int,
[col1] varchar(1),
[col2] varchar(1),
[col3] varchar(2),
[col4] varchar(2),
[col5] varchar(2));
insert into #test ([ID], [col1], [col2], [col3], [col4], [col5])
values
(1, 'Y', 'G', 'CA', 'DA', 'EA'),
(2, 'Y', 'G', 'CA', 'DA', 'EA'),
(3, 'Y', 'Q', 'CA', 'DA', 'EA'),
(1, 'X', 'G', 'RA', 'DA', 'EA'),
(2, 'X', 'G', 'CA', 'DA', 'EA'),
(3, 'X', 'Q', 'CA', 'DA', 'EA');
-- create the output table
select
distinct ID, col3, col4, col5,
'N' as col1_X, 'N' as col1_Y, 'N' as col2_G, 'N' as col2_Q
into #result
from #Test;
-- update the results
update t1
set t1.col1_X = 'Y'
from #result t1
where exists (select * from #test t2
where t2.ID = t1.ID and t2.col3 = t1.col3 and t2.col4 = t1.col4 and t2.col5 = t1.col5
and t2.col1 = 'X');
update t1
set t1.col1_Y = 'Y'
from #result t1
where exists (select * from #test t2
where t2.ID = t1.ID and t2.col3 = t1.col3 and t2.col4 = t1.col4 and t2.col5 = t1.col5
and t2.col1 = 'Y');
update t1
set t1.col2_G = 'Y'
from #result t1
where exists (select * from #test t2
where t2.ID = t1.ID and t2.col3 = t1.col3 and t2.col4 = t1.col4 and t2.col5 = t1.col5
and t2.col2 = 'G');
update t1
set t1.col2_Q = 'Y'
from #result t1
where exists (select * from #test t2
where t2.ID = t1.ID and t2.col3 = t1.col3 and t2.col4 = t1.col4 and t2.col5 = t1.col5
and t2.col2 = 'Q');
select * from #result;