I'm looking for a way to search multiple columns for a specific list of values.
Here is some test data with 3 columns of data:
WITH fieldstosearch AS
(SELECT 'R10.10' as field1, 'R10.11' as field2 , 'R15.11' as field3 UNION ALL
SELECT 'R10.10', 'R20.3', 'R33.33' UNION ALL
SELECT 'R20.0', 'R20.1', 'R33.33' UNION ALL
SELECT 'R10.15', 'R20.4', 'R33.33' UNION ALL
SELECT 'R10.11', 'R10.10', 'R33.33')
I can successfully search 1 column at a time (ex. field1) with a list of values using the REGEXP_CONTAINS function like this:
SELECT REGEXP_CONTAINS(field1, 'R10.10|R07.82|R07.89|R07.9')
FROM fieldstosearch
I was hoping to maybe use the CONTAINS_SUBSTR function to search 'multiple' columns for a specific list of values like this, but the syntax is off/is not working:
SELECT CONTAINS_SUBSTR((field1, field2, field3), 'R10.10', 'R07.82', 'R07.89', 'R07.9')
FROM fieldstosearch
I can search multiple columns, with 1 search string/value like this:
SELECT CONTAINS_SUBSTR((field1, field2, field3), 'R10.10')
FROM fieldstosearch
So it seems like there might be a way to select multiple search values to the CONTAINS_SUBSTR function?
Does anyone have any tricks/ideas of a way to achieve this in BigQuery?
Thanks!
You can use below approach
select *,
regexp_contains(format('%t',(field1, field2, field3)), 'R10.10|R07.82|R07.89|R07.9')
from fieldstosearch
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.