with test1
as
(
select 'EQ1' as code, '대정수' as item , '2001-08-15' as dtm from dual
union
select 'EQ1' as code, '소정수' as item , '2001-11-15' as dtm from dual
union
select 'EQ1' as code, '대정수' as item , '2002-02-15' as dtm from dual
union
select 'EQ1' as code, '소정수' as item , '2002-04-15' as dtm from dual
union
select 'EQ1' as code, '고정수' as item , '2001-07-15' as dtm from dual
)
SELECT CODE, item
, MAX(DECODE(SUBSTR(dtm, 0, 4), '2001', '_O', 'X' )) as "2001"
, MAX(DECODE(SUBSTR(dtm, 0, 4), '2002', '_O', 'X' )) as "2002"
, MAX(DECODE(SUBSTR(dtm, 0, 4), '2003', '_O', 'X' )) as "2003"
from test1
group by CODE, item