-1

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
James Z
  • 12,209
  • 10
  • 24
  • 44

1 Answers1

2

Please try this in MySql

SELECT name, SUBSTRING_INDEX(name, '-', -1) AS new_name, age, gender FROM your_table;
Kirs Sudh
  • 373
  • 2
  • 15
Mobeen
  • 69
  • 7