1

I have a column called desc and it contains the below string :

BUY 20 SAVE 5

Desired output: 20

I tried:

SELECT
   desc,
   split (desc, 'Y\\s')[1] as Revenue
FROM table1;
Mona
  • 273
  • 1
  • 2
  • 13
  • Use `regexp_extract()` to extract the numbers, or use `substr()` to extract that if the position is same always. – samkart Dec 29 '19 at 20:23

1 Answers1

1

Using Hive regexp_extract(string subject, string pattern, int index) function:

SELECT regexp_extract(desc, '.*? (\\d+) .*$', 1) AS Revenue
  FROM table1

See other examples in:

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250