我在BigQuery中有很多具有不同表后缀的表,其中每个表在每行中都有四个级别的结构。 我进行查询以将其取消嵌套到展平表中。
SELECT
report_date,
tracker,
source,
countryCode,
stageNum,
bundleId,
offer_name,
places.name AS site_id,
places.clicks,
places.cost,
places.p_leads_v2_
FROM (
SELECT
report_date,
tracker,
source,
countryCode,
stageNum,
bundleId,
offer.name AS offer_name,
offer.places
FROM (
SELECT
report_date,
tracker,
source,
campaigns.countryCode,
campaigns.stageNum,
campaigns.bundleId,
campaigns.offer
FROM
`dv3.tracker_recording.records_*` AS t,
t.campaigns ) AS t1,
t1.offer) AS t2,
t2.places
它工作正常,但效果不是很好,因为它似乎太长了。如何使它更简单,更有效? 有什么建议。谢谢。
答案 0 :(得分:2)
您是否尝试过类似的查询?
SELECT
report_date,
tracker,
source,
c.countryCode,
c.stageNum,
c.bundleId,
o.name as offer_name,
p.name AS site_id,
p.clicks,
p.cost,
p.p_leads_v2_
FROM `dv3.tracker_recording.records_*` as t, UNNEST(t.campaigns) as c, UNNEST(c.offer) as o, UNNEST(o.places) as p