1
문자열의 고유 바이트 수를 계산하려고합니까?하이브를 사용하여 문자열에서 고유 한 정수를 계산하는 방법은 무엇입니까?
데이터 (숫자 만 바이트 예를 들어, 전화 번호) :
1234567890
1111111112
결과 : 나는 아래 시도하고 합 때문에 작동하지 않았다
10
2
()는 인 경우 UDF를 허용하지 않으므로 '이라고 생각합니다.
select phone
, sum(
cast(if(length(regexp_replace(phone,'0',''))<10,'1','0') as int) +
cast(if(length(regexp_replace(phone,'1',''))<10,'1','0') as int) +
cast(if(length(regexp_replace(phone,'2',''))<10,'1','0') as int) +
cast(if(length(regexp_replace(phone,'3',''))<10,'1','0') as int) +
cast(if(length(regexp_replace(phone,'4',''))<10,'1','0') as int) +
cast(if(length(regexp_replace(phone,'5',''))<10,'1','0') as int) +
cast(if(length(regexp_replace(phone,'6',''))<10,'1','0') as int) +
cast(if(length(regexp_replace(phone,'7',''))<10,'1','0') as int) +
cast(if(length(regexp_replace(phone,'8',''))<10,'1','0') as int) +
cast(if(length(regexp_replace(phone,'9',''))<10,'1','0') as int)
) as unique_bytes
from table;
해결책으로 정규 표현식에 사용되지 않습니다.
고든, 빠른 응답에 감사드립니다. 방정식의 합계가 필요 없습니다. 나는 입국을 택한 직후에 거의 깨달았다. 그러나 솔루션은 훨씬 더 나은 경로를 따라 가고 있으며 더 효율적입니다! 감사. – invoketheshell
게시 할 때 총액 문제가 발생했습니다. 바보 나. 'if'부분은 문자열을 반환하므로 정수로 캐스팅됩니다. 지금까지 regexp_replace를 대체 할 apposed로 사용하는 경우, 저는 많은 정규 표현식을 사용하고 습관을 기본값으로 사용하고있었습니다. 솔루션에 다시 한번 감사드립니다. 그것은 내 것보다 더 효율적이다. 나는 그것을 보았 더라면 좋겠다. 건배. – invoketheshell