我收到错误:
Correlated subqueries that reference other tables are not supported unless they can be de-correlated, such as by transforming them into an efficient JOIN
在以下查询
上(SELECT DISTINCT video_id,
COALESCE(custom_id,
(SELECT custom_id FROM `test2.channel_map` b
WHERE a.channel_id = b.channel_id LIMIT 1),
'Default')
FROM `test2.revenue` a)
我实际上是在尝试将null custom_ids替换为查找表中的另一个custom_id。有没有比BigQuery更好的方法可以接受?
答案 0 :(得分:3)
只需使用常规LEFT JOIN - 如下所示
SELECT DISTINCT video_id,
COALESCE(
a.custom_id,
b.custom_id,
'Default'
)
FROM `test2.revenue` a
LEFT JOIN `test2.channel_map` b
ON a.channel_id = b.channel_id