Mysql
 sql >> Base de données >  >> RDS >> Mysql

Diviser la chaîne en ligne

CREATE TABLE new_table
SELECT SUBSTRING(name,  1, 4) as field, class_code FROM old_table
UNION
SELECT SUBSTRING(name,  6, 4) as field, class_code FROM old_table
UNION
SELECT SUBSTRING(name, 11, 4) as field, class_code FROM old_table
UNION
SELECT SUBSTRING(year,  1, 4) as field, class_code FROM old_table
UNION
SELECT SUBSTRING(year,  6, 4) as field, class_code FROM old_table