我想在以下查询中找到Info2和Info3。如何在BigQuery中为同一个表执行此操作。 Info3也有类似于info2的条件。
谢谢!
ID | startDate | endDate | info1 | info2 | info 3
----------------------------------------------------
1 | 11-12-2000 | 11-12-2010 | Blue | Circle | A
| Triangle | B
| Square |
----------------------------------------------------
2 | 11-12-2001 | 11-12-2011 | Yellow | <*> | C
----------------------------------------------------
3 | 11-12-2007 | 11-12-2008 | Brown | Circle | D
| Triangle | B
----------------------------------------------------
INFO2 =&#34;!&LT * GT;&#34; AND inf3 = B
ID | startDate | endDate | info1 | info2 | info 3
----------------------------------------------------
1 | 11-12-2000 | 11-12-2010 | Blue | Circle | B
1 | 11-12-2000 | 11-12-2010 | Blue | Triangle | B
1 | 11-12-2000 | 11-12-2010 | Blue | Square | B
----------------------------------------------------
3 | 11-12-2007 | 11-12-2008 | Brown | Circle | B
3 | 11-12-2007 | 11-12-2008 | Brown | Triangle | B
----------------------------------------------------
以下查询无法使用Info3。
#standard_SQL
SELECT
id,
startDate,
endDate,
info1,
info2,
info3
FROM
`MY_DB`
WHERE
EXISTS (
SELECT
Info2
FROM
UNNEST(Info2) Temp
WHERE
Temp NOT IN ("<*>"))
答案 0 :(得分:4)
以下是BigQuery Standard SQL
#standardSQL
WITH `project.dataset.MY_DB` AS (
SELECT 1 id, '11-12-2000' startDate, '11-12-2010' endDate, 'Blue' info1, ['Circle','Triangle', 'Square'] info2, ['A', 'B'] info3 UNION ALL
SELECT 2, '11-12-2001', '11-12-2011', 'Yellow', ['<*>'], ['C'] UNION ALL
SELECT 3, '11-12-2007', '11-12-2008', 'Brown', ['Circle','Triangle'], ['D', 'B']
)
SELECT id, startDate, endDate, info1, info2, info3
FROM `project.dataset.MY_DB`, UNNEST(info2) info2, UNNEST(info3) info3
WHERE info2 != '<*>' AND info3 = 'B'
ORDER BY id
结果如下
Row id startDate endDate info1 info2 info3
1 1 11-12-2000 11-12-2010 Blue Circle B
2 1 11-12-2000 11-12-2010 Blue Triangle B
3 1 11-12-2000 11-12-2010 Blue Square B
4 3 11-12-2007 11-12-2008 Brown Circle B
5 3 11-12-2007 11-12-2008 Brown Triangle B