MySQL:多次传递字符串连接

时间:2017-05-16 06:11:09

标签: mysql concatenation

全部,   我在MySQL中有一个表,其中包含以下示例数据

  

MYDB.DUMMYTABLE

SampleColumn
a
b
c
bd
be
bf
cgj
chk
cil

我试图实现以下结果集

cgj
chk
cil
cgjbd
chkbe
cilbf

我如何首先选择长度等于X(三个)的所有数据然后在下一个传递中连续相同的字段,其中所有数据的长度等于Y(两个)以获得输出,如图所示以上?

1 个答案:

答案 0 :(得分:0)

您可以使用联接,例如:

select concat(nt2.col1, nt1.col1)
from new_table as nt1
inner join new_table as nt2
   on length(nt2.col1) = 2
where length(nt1.col1) = 3

Sql fiddle:http://sqlfiddle.com/#!9/ebd5c1/3/0