在谷歌的bigquery,讓我說我想嘗試找到一個完全匹配(例如:通過郵政編碼),但如果我失敗了,根據說城市+狀態得到另一個更接近的匹配+國家。如何構建一個查詢來返回一個結果
因此,像:
select *
from locations
where
Target_Type = "Postal Code" and
Name = "L4A" and
Country_Code = "CA"
or
(
Name = "Toronto" and
Target_Type = "City" and
Country_Code = "CA"
)
這將返回兩個,我想只是第一場比賽,第二隻在第一場比賽失敗。
如何做到這一點?
你確定你的答案適用於BigQuery的?我收到錯誤無法識別令牌UNION。 – Carmageddon
我不熟悉大查詢,但看起來像支持'UNION ALL' https://chartio.com/resources/tutorials/how-to-union-queries-in-google-bigquery/ –
@Carmageddon它應該工作。嘗試在查詢的開始部分添加#standardSQL –