我需要从“位置”列中获取一个由“城市,州”组成的地址,并填充 2 个新列“城市”和“州”,但保持原样,现在我已经使用 SUBSTRING_INDEX 命令完成了此操作,但我每次都必须运行命令才能做到这一点,我怎样才能让它坚持下去?
这是我的子字符串代码:
SELECT distinct id, first_name, last_name,
SUBSTRING_INDEX(location, ' ,', 1) AS City,
SUBSTRING_INDEX(location, ' ,', -1) AS State,
SUBSTRING_INDEX(seeking, ' ,', 1) AS Seeking_1,
SUBSTRING_INDEX(seeking, ' ,', -1) AS Seeking_2,
SUBSTRING_INDEX(interests,' ,', 1) AS Interests_1,
SUBSTRING_INDEX(interests,' ,', -1) AS Interests_2,
SUBSTRING_INDEX(interests,' ,', 1) AS Interests_3
FROM my_contacts