在mysql表中组合多个行值

时间:2014-06-06 06:39:07

标签: mysql

如何在mysql表中获取以下输出?

来源表:

   id  values
    1    a
    2    b
    3    c
    4    d
    5    e

结果:

id  values
1    a
2    ab
3    abc
4    abcd
5    abcde

1 个答案:

答案 0 :(得分:1)

SELECT  a.id, (@inc := concat(@inc, a.name)) AS Name
FROM  mytable a, (SELECT @inc:= '') c ORDER BY a.id ASC

SQLFIDDLE DEMO