You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@hive.apache.org by "איל (Eyal)" <ey...@gmail.com> on 2010/11/04 15:05:06 UTC

longest matching prefix

Hi,

In MySQL to match '12684041234' to the longest prefix I would do

SELECT num_prefix
FROM nums
WHERE '12684041234' LIKE CONCAT(num_prefix, '%')
AND LENGTH(num_prefix) = (
SELECT MAX(LENGTH(num_prefix))
FROM nums
WHERE '12684041234' LIKE CONCAT(num_prefix, '%')
)

** Table nums has a column named num_prefix with prefix values.

How can I do it in hive ?