MySQL重新调整字符串内字符的顺序
1.创建排序表
CREATE TABLE `letters` (
`letter` char(1) NOT NULL,
PRIMARY KEY (`letter`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2.插入排序字符
INSERT INTO `letters` (`letter`) VALUES
('a'),('b'),('c'),('d'),('e'),('f'),('g'),('h'),('i'),('j'),('k'),('l'),('m'),
('n'),('o'),('p'),('q'),('r'),('s'),('t'),('u'),('v'),('w'),('x'),('y'),('z');
3.使用position函数用待排序的表与排序表之间创建关系
select a.ksh,a.kstzdm,GROUP_CONCAT(b.letter ORDER BY b.letter ASC SEPARATOR '') AS ndm
FROM t_bmk a LEFT JOIN letters b ON POSITION(b.letter IN a.kstzdm) > 0
GROUP BY a.ksh,a.kstzdm
4.验证结果
5.此方法也可以应用到sqlserver,oracle数据库上。