Extract data from a string sql

2019-07-26 07:19发布

How would the regexp_extract change if this data was in a column named "pages" and I want for every row that has ':old:yes:' to return the string after 'yes:' and before the next string?

PAGES (table name)

hello:ok:old:yes:age:test:jack   
hello:no:old:yes:hour:black:nancy   
hi:fine:old:yes:minute:white:jason   

As you can see ':old:yes:' is my starting point and i want the regexp_extract to return the next text before the colon. In the above example I would want the following results:

age  
hour  
minute 

标签: sql hive hiveql
1条回答
对你真心纯属浪费
2楼-- · 2019-07-26 07:40
select  regexp_extract(page,':old:yes:([^:]+)',1)
from    pages
where   page like '%:old:yes:%'

+--------+
| age    |
| hour   |
| minute |
+--------+
查看更多
登录 后发表回答