0

我想知道是否有任何选项可以将多行输出到单行中。

例如,常规select * from tbl_name将给出表中所有可用记录的列表。

firstname    lastname
----------   ------------
Lepanto      Fernando
Lourdes      Brillianto
Gerald       Siluvai

首选输出

名字将有 -> Lepanto###Lourdes###Gerald

姓氏将有 -> Fernando###Brillianto###Siluvai

我们可以做一些连接来实现上述目标吗?

4

2 回答 2

0

使用GROUP_CONCAT()

select group_concat(firstname separator '###') as firstnames,
       group_concat(lastname separator '###') as lastnames
from your_table
于 2013-06-12T13:21:59.807 回答
0

利用:

select GROUP_CONCAT(firstname SEPARATOR "###") as firstname,
       GROUP_CONCAT(lastname SEPARATOR "###") as lastname
from tblname
于 2013-06-12T13:23:01.063 回答