table = get_table_from_db() tmp = {} state = false table.each do |line| if ( !state || state != line['APP_ID'] ) state = line['APP_ID'] tmp['APP_ID'] = line else tmp['APP_ID']['SERVER'].join(',' line['SERVER']) end end return tmp