select resid, delay, discard from (select a.resid, sum(decode(a.ditemid, 'aaa', a.value, '')) || sum(decode(a.ditemid, 'B_WebDNSDW', a.value, '')) delay, sum(decode(a.ditemid, 'B_WebTCPDelayW', a.value, null)) || sum(decode(a.ditemid, 'bbb', a.value, '')) discard from (select resid, ditemid, value from rmcinfo t where ditemid IN ('B_WebDNSDW', 'B_WebTCPDW') and resid = 'APP02op7') a group by a.resid)