Imagine we have the following table.
The result we would like to acquire is:
Names and values are concatenated into strings and grouped by id. We need an aggregate function,
that concatenates strings for that. Here are some solutions for different sql databases.
This case is most easy one. Lucky users already have the GROUP_CONCAT(expr) function. This
query should give the answer.
The solution here is a bit more difficult, but nevertheless easy enough. We need to create our own
aggregate function and use it in our query.
Here we used already existing function to concatenate text fields textcat, but we could write
Since version 2005 it became also possible to write your own aggregate function in MsSql, but here
I provide another solution using inner select and xml path.
comments powered by