sql - Impala Query: Find value in pipe-separated list -
i have column containing rows of pipe separated string values:
| cola | ___________ | 5|4|2|255 | | 5|4|4|0 | | 5|4|4|3 | | 5|4|4|4 |
i need create query select rows contain 4 or 5, never 2 or 3. along lines of:
select t.cola my_table t (t in ("4", "5") , t not in ("2","3")
resulting in:
| cola | ___________ | 5|4|4|0 | | 5|4|4|4 |
i ended using combination of 2 answers below, using either method alone still left me rows containing "255". here's final query:
select t.cola my_table t (t.cola in ('4', '5') or t.cola "%|5|%" or t.cola "%|5" or t.cola "5|%") , t.cola not "%3%" , t.cola not "%|2|%" , t.cola not regexp "^2|%" , t.cola not regexp "%|2$"
there more elegant way this, trick.
what using like
function ?
where (t '%4%' or t '%5%') , (t not '%2%' , t not '%3%')
that should job.
Comments
Post a Comment