简体   繁体   中英

Athena View - Need to get a specific value from a column's original value

I am creating a view in athena from athena table where I need to get a substring from a column value. I have a column where values are like below:

|12 MO ABC 14.99APR /1.20PMT|

|36 MO ABC 14.99%APR /1.20%PMT|

|36 MO ABC 14.99% APR /1.20%|

|14 MONTH ABC 9.99%APR /8.79%|

|14 MONTH ABC DEF 9.10% APR |

From these values I need to get only highlighted APR value. How can we get it?

You can use:

SELECT regexp_extract('|36 MO ABC **14.99% APR**/1.20%PMT|', '[\d.%]+ APR')

It will return:

14.99% APR

If the space before APR is sometimes missing, you can use:

SELECT regexp_extract('|14 MONTH ABC9.99%APR/8.79%|', '[\d.%]+ ?APR')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM