英文:
How to split one column into 2 columns in MySQL for hive table?
问题
我想将名字列拆分成两列,当名字中有许多连字符(-)时,我想在MySQL中从最后一个连字符(-)处拆分,这是在Hive数据库中进行的。
例如,检查下表:
name | age | gender |
---|---|---|
a-b-c-d_b | 23 | M |
d-e-f-g_e | 44 | F |
我希望输出结果只拆分名字列的最后一个(-)。
因此,输出表应该像下面这样:
name | new_name | age | gender |
---|---|---|---|
a-b-c-d_b | d_b | 23 | M |
d-e-f-g_e | g_e | 44 | F |
英文:
I want to split the name column into 2 columns where there are many hiphens(-) in the name but I want to split from the last hiphen(-) in MySQL in hive db.
for example check the check the below table
name | age | gender |
---|---|---|
a-b-c-d_b | 23 | M |
d-e-f-g_e | 44 | F |
I want the output to be like splitting the name column with only last (-)
So the output table should be like the one below
name | new_name | age | gender |
---|---|---|---|
a-b-c-d_b | d_b | 23 | M |
d-e-f-g_e | g_e | 44 | F |
答案1
得分: 2
请尝试在MySQL中运行以下查询:
SELECT name, SUBSTRING_INDEX(name, '-', -1) AS new_name, age, gender FROM your_table;
英文:
Please try this in MySql
SELECT name, SUBSTRING_INDEX(name, '-', -1) AS new_name, age, gender FROM your_table;
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论