6.12 按字母顺序排列字符串
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了6.12 按字母顺序排列字符串相关的知识,希望对你有一定的参考价值。
问题:如下的结果集:
+--------+
| ename |
+--------+
| ALLEN |
| WARD |
| MARTIN |
| BLAKE |
| CLARK |
| KING |
| TURNER |
| JAMES |
| MILLER |
+--------+
需要结果如下:
+--------+-----------------------------------------+
| ename | group_concat(c order by c separator ‘‘) |
+--------+-----------------------------------------+
| ALLEN | AELLN |
| BLAKE | ABEKL |
| CLARK | ACKLR |
| JAMES | AEJMS |
| KING | GIKN |
| MARTIN | AIMNRT |
| MILLER | EILLMR |
| TURNER | ENRRTU |
| WARD | ADRW |
+--------+-----------------------------------------+
解决方案:
select ename,group_concat(c order by c separator ‘‘)
from (
select ename,substr(a.ename,iter.pos,1) c
from emp a,
(select id pos from t10) iter
where iter.pos <=length(a.ename)
) x
group by ename;
+--------+-----------------------------------------+
| ename | group_concat(c order by c separator ‘‘) |
+--------+-----------------------------------------+
| ALLEN | AELLN |
| BLAKE | ABEKL |
| CLARK | ACKLR |
| JAMES | AEJMS |
| KING | GIKN |
| MARTIN | AIMNRT |
| MILLER | EILLMR |
| TURNER | ENRRTU |
| WARD | ADRW |
+--------+-----------------------------------------+
以上是关于6.12 按字母顺序排列字符串的主要内容,如果未能解决你的问题,请参考以下文章