I haven’t tested this so it may not be perfect, it’s just off the top of my head.
If you are using Oracle the Decode function will help you out, otherwise a case statement should do the trick for most other db’s. I am not sure if there is a way you can do this more dynamically ie not specify ‘XX’ and ‘YY’. But this is probably the easiest way I know of.
myResults.col3 as col3,
sum(CASE WHEN myResults.col1 = ‘XX’ then myResults.col2 ELSE 0 END) as ‘XX’,
sum(CASE WHEN myResults.col1 = ‘YY’ then myResults.col2 ELSE 0 END) as ‘YY’
SELECT myTable.col1 as col1
,sum(myTable.col2) as col2
,myTable.col3 as col3
GROUP BY myTable.col1, myTable.col3