简体   繁体   English

大查询中列的结构值

[英]Struct values to columns in big query

I have a column "device" which have struct values in every row我有一列“设备”,每一行都有结构值

device设备

(row 1) (第 1 行)

brand_name品牌 brand_id品牌编号 country国家
huawei华为 34j0 34j0 china中国

(row 2) (第 2 行)

brand_name品牌 brand_id品牌编号 country国家
sony索尼 ds5g ds5g japan日本

we can create column from these structs by doing this我们可以通过这样做从这些结构创建列

SELECT
device.brand_name 
device.brand_id 
device.country 
from table

In this case struct only have three values ( brand_name,brand_id, country) but what if the struct have n number of values, so what i want to do is instead of accessing every value in struct by devicedevice.brand_name,device.brand_id....etc, I want to loop all the values inside it and make it as a column, is there a way to do it?在这种情况下,结构只有三个值(brand_name、brand_id、country)但是如果结构有 n 个值怎么办,所以我想做的不是通过 devicedevice.brand_name、device.brand_id 访问结构中的每个值。 ..等等,我想循环其中的所有值并将其作为一列,有没有办法做到这一点? , thank you , 谢谢你

You can just use the wildcard symbol * .您可以只使用通配符* More specifically:进一步来说:

WITH devices as (
SELECT STRUCT("sony" as brand_name, "ds5g" as brand_id, "japan" as country) as device UNION ALL
SELECT STRUCT("huawei" as brand_name, "34j0" as brand_id, "china" as country) as device
)

SELECT device.* FROM devices

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM