如何在配置单元中删除特殊字符后的值

时间:2017-04-19 06:52:02

标签: sql hadoop hive hiveql

我正在使用列状态为

的配置单元表
**state**
taxes, TX
Washington, WA
New York, NY
New Jersey, NJ

现在我想分开状态列,我想把它写在新列中

**state**             **code**
taxes                   TX
Washington              WA
New York                NY
New Jersey              NJ

2 个答案:

答案 0 :(得分:2)

select  split(state,',')[0]         as state
       ,ltrim(split(state,',')[1])  as code

from    mytable
+------------+------+
|   state    | code |
+------------+------+
| taxes      | TX   |
| Washington | WA   |
| New York   | NY   |
| New Jersey | NJ   |
+------------+------+

答案 1 :(得分:0)

选择substr(name,0,instr(name,',') - 1),substr(name,instr(name,',')+ 1,10 )来自aa