是否可以在 BigQuery 中執行以下操作?
SELECT country, id FROM
-- possible to in-line this, with an array or struct even?
[['us', 1], ['ca',2]] AS country (country, id)
或者也許有更好的方法來做到這一點?目前我這樣做的方式如下,但我想看看是否可以將其行內到FROM
:
WITH country AS (
SELECT 'us' AS country, 1 as id UNION ALL
SELECT 'ca', 2
)
uj5u.com熱心網友回復:
另一種可能的選擇是使其成為ARRAY<STRUCT<>>型別。考慮如下:
SELECT * FROM UNNEST([
STRUCT('us' AS country, 1 AS id),
STRUCT('ca',2)
]);
uj5u.com熱心網友回復:
一種方法是在 UNNEST 上進行交叉連接,然后按陣列的偏移量進行過濾。請注意,在這種情況下,陣列是列而不是行:
SELECT country, id FROM
UNNEST(["us", "ca"]) country WITH OFFSET o0,
UNNEST([1,2]) id WITH OFFSET o1
WHERE o0=o1 -- normalize all unnests
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/491563.html
上一篇:SQL-過濾掉欄位名
下一篇:如何復制同一列的前一行值?