CREATE TABLE test20 (en_name VARCHAR(100));
INSERT INTO test20 SELECT '100105516_100105517';
INSERT INTO test20 SELECT '100105516_100105518';
INSERT INTO test20 SELECT '100105767_100105771';
INSERT INTO test20 SELECT '100105803_100105804';
INSERT INTO test20 SELECT '100105846_100105848';
INSERT INTO test20 SELECT '100105851_100105854';
INSERT INTO test20 SELECT '100106979_100106980';
INSERT INTO test20 SELECT '100107076_100107077';
INSERT INTO test20 SELECT '100118835';
INSERT INTO test20 SELECT '100117241';
INSERT INTO test20 SELECT '100117262';
INSERT INTO test20 SELECT '100107183';
INSERT INTO test20 SELECT '100107197';
INSERT INTO test20 SELECT '';
INSERT INTO test20 SELECT '';
INSERT INTO test20 SELECT '';
方法一:
SELECT en_name,
IF(LOCATE('_',en_name)=0,CONCAT(SUBSTRING_INDEX(en_name,'_',1)+100000000 ),CONCAT(SUBSTRING_INDEX(en_name,'_',1)+100000000,'_',SUBSTRING_INDEX(en_name,'_',2)+100000000))
FROM test20;
方法二:
SELECT en_name,
CASE WHEN en_name LIKE "%\_%"
THEN CONCAT(SUBSTRING_INDEX(en_name,'_',1)+100000000,'_',SUBSTRING_INDEX(en_name,'_',-1)+100000000)
ELSE CONCAT(SUBSTRING_INDEX(en_name,'_',1)+100000000 )
END AS en_name
FROM test20;