Given data such as
Type Value
A This
A is
B Will
A 开发者_Go百科 a
B this
A test
B work
I would like to end up with
Type Value
A This is a test
B Will this work
Is this possible? Thanks!
Use GROUP_CONCAT().
SELECT Type, GROUP_CONCAT(Value SEPARATOR ' ') AS Value
FROM MyTable
GROUP BY Type;
Ensuring the words are concatenated in the order you want can be tricky, however. GROUP_CONCAT()
has an ORDER BY
clause (see the docs) but your example doesn't include any column that can be used to determine the order. Relying on the physical storage order isn't reliable.
精彩评论