sql - PostgreSQL integer array value join to integer in other table with desc string -
i have table test column int arrays , values {1000,4000,6000} or {1000} or {1000,4000} called ekw. these values match description string in table
tab: test id | name | ekw ----------------- 1 | 1 | {1000} 2 | 2 | {1000,4000} 3 | 3 | {1000,4000,6000} tab: ekwdesc id | value | desc ----------------- 1 | 1000 | max 2 | 2000 | tim 3 | 3000 | rita 5 | 4000 | sven 6 | 5000 | tom 7 | 6000 | bob is possible select these columns , print strings?
something like:
select name, ekw test, ekwdesc i see result:
id | name | ekwdesc ----------------- 1 | 1 | max 2 | 2 | max, sven 3 | 3 | max, sven, bob i tried in , couldn't work.
you had right idea use any operator join. once join complete, that's left use string_agg transform result format want:
select name, string_agg(description, ', ') test join ekwdesc on ekwdesc.value = any(test.ekw) group name see attached sqlfiddle executable example.
Comments
Post a Comment