我有一个查询如下。 Select split(Salary, '\|') as salaryEmp from tableA
它工作正常,并为我提供了一个数组字符串["1089","1078"]
。
我想添加此数组字符串的值。我无法将其转换为整数并将它们相加。可以为此建议一种合适的方式。
答案 0 :(得分:0)
使用explode()
+ lateral view
:
select sum(cast(salary as int)) sum_salry from
(
select split('1089|1078', '\\|') SalaryArray
) s lateral view explode (SalaryArray) a as Salary;
OK
2167
答案 1 :(得分:0)
select sum(e.col) as sum_Salary
from salaryEmp lateral view explode (split(Salary,'\\|')) e
+------------+
| sum_salary |
+------------+
| 2167 |
+------------+