我有一个hive SQL,如下所示返回以下输出,现在我想从数组中得到第一个not null值,即" 11"。
SQ ::
选择cod_cust,split(反向(concat_ws('',collect_list) acc_status ='休眠'然后" 1"别的" 0"结束))),' 0')来自的状态 account_status group by cod_cust;
输出:
cod_cust status
1023 [""," 11"," 1"," 111","", ""]
2209 [""," 11"," 1"," 111","", ""]
答案 0 :(得分:2)
不使用split
函数,输出将如下所示:
cod_cust status
1023 01101011100
2209 01101011100
所以任务是找到1
的第一个子序列,可以通过regexp_extract
来解决。您也可以使用IF
代替CASE
:
SELECT cod_cust,
regexp_extract(reverse(concat_ws('', collect_list(if((acc_status='Dormant'), '1', '0'))), '1+', 0) first_element
status
FROM account_status
GROUP BY cod_cust;