MySQL以点为单位连接最后一项

时间:2016-11-02 18:19:14

标签: mysql concatenation

我有表订单

我想

select (OrderName) Values Concatenated by (dash) While last OrderName Concatenated by (Dot)

我使用了以下内容:SELECT CONCAT(OrderName , ' - ') AS 'Name' FROM Orders

示例:

order1 - order2 - order3 .

1 个答案:

答案 0 :(得分:0)

只需使用GROUP_CONCAT

即可
 SELECT CONCAT ( SUBSTRING(`Name`, 1, CHAR_LENGTH(`Name`) - 2),
                 ' . ') as `Name`
 FROM (
           SELECT GROUP_CONCAT(OrderName, ' - ') AS `Name`
           FROM Orders
      ) T