have a table in vertica: test like this:
ID | name
1 | AA
2 | AB
2 | AC
3 | AD
3 | AE
3 | AF
how could I use an aggregate function or how to write a query to get data like this (vertica syntax)?
ID | ag
1 | AA
2 | AB, AC
3 | AD, AE, AF
First, you'll need to compile the udx for
agg_concatenate
.Then you can do a query like:
Uses rtrim to get rid of the last ', '.
If you need the aggregate to be sorted a certain way, you may need to select/sort in an inline view or with first.
The other method is to use
GROUP_CONCAT
from the strings package on github.However there are some limitations with this method since analytical udx won't allow you to include other aggregates (and you'll have to inline it or use with to add more data to it).