开发者

SQL Group by - Listing all rows by group?

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜