select id, cd, nm , sum(decode(file_cs,'01',1)) fc01 , sum(decode(file_cs,'02',1)) fc02 , sum(decode(file_cs,'03',1)) fc03 , sum(decode(file_cs,'04',1)) fc04 , sum(decode(file_cs,'05',1)) fc05 , sum(decode(file_cs,'06',1)) fc06 from ( select a.id, a.cd, a.nm, b.file_cs from ori a, orifile b where a.id = b.id ) group by id, cd, nm