0

I have the following table

Userid  District_code
1        05
1        03
2        03
2        04
3        06

and want to get this output:

userid=1 dist_code(05,03)
  • It looks like you're wanting to do string aggregation. – Colin 't Hart May 24 at 10:05
2
SELECT 'userid=' || Userid::text
     , 'dist_code(' || string_agg(District_code::text, ',') || ')'
FROM table
GROUP BY Userid
-- WHERE userid=1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.