使用品牌資料編寫查詢

地點洞察提供許多類別地點的品牌資訊。例如:

  • 在「自動櫃員機、銀行和信用合作社」類別中,品牌資料包含 PNC、UBS 和 Chase 銀行等各個品牌的項目。
  • 以「汽車租賃」類別為例,資料會包含 Budget、Hertz 和 Thrifty 這幾個品牌的項目。

查詢品牌資料集的一般用途是將其與地點資料的查詢聯結,以回答下列問題:

  • 某個區域中各品牌的商店數量為何?
  • 該區域中前三大競爭對手品牌的數量為何?
  • 該區域內特定類別的品牌數量,例如「健身」或「加油站」?

品牌資料集簡介

美國的品牌資料集名稱為 places_insights___us___sample.brands

品牌資料集架構

品牌資料集的結構定義會定義三個欄位:

  • id:品牌 ID。
  • name:品牌名稱,例如「Hertz」或「Chase」。
  • category:品牌類型,例如「加油站」、「食品和飲料」或「住宿」。如需可能值的清單,請參閱「類別值

在查詢中使用品牌資料集

地點資料集架構會定義 brand_ids 欄位。如果地點資料集中的地點與品牌相關聯,則該地點的 brand_ids 欄位會包含相應的品牌 ID。

參照品牌資料集的典型查詢會根據 brand_ids 欄位,對地點資料集執行 JOIN

舉例來說,如要找出紐約市帝國大廈 2000 公尺範圍內的麥當勞餐廳數量,請執行下列步驟:

SELECT WITH AGGREGATION_THRESHOLD
 COUNT(*)
FROM places_insights___us___sample.places_sample places, UNNEST(brand_ids) AS brand_id
LEFT JOIN places_insights___us___sample.brands ON brand_id = brands.id
WHERE
ST_DWITHIN(ST_GEOGPOINT(-73.9857, 40.7484), point, 2000)
AND brands.name = "McDonald's"
AND business_status = "OPERATIONAL"

下一個查詢會傳回紐約市屬於某個品牌的咖啡廳數量,並依品牌名稱分組:

SELECT WITH AGGREGATION_THRESHOLD
  brands.name,
  COUNT(*) AS store_count
FROM places_insights___us___sample.places_sample places, UNNEST(brand_ids) AS brand_id
LEFT JOIN places_insights___us___sample.brands ON brand_id = brands.id
WHERE brands.category = "Food and Drink"
AND "cafe" IN UNNEST(places.types)
AND business_status = "OPERATIONAL"
GROUP BY brands.name
ORDER BY store_count DESC;

下圖顯示各品牌的數量:

依品牌分組的 CFE 計數查詢結果。

類別值

品牌的 category 欄位可能包含下列值:

類別類型值
ATMs, Banks and Credit Unions
Automotive and Parts Dealers
Automotive Rentals
Automotive Services
Dental
Electric Vehicle Charging Stations
Electronics Retailers
Fitness
Food and Drink
Gas Station
Grocery and Liquor
Health and Personal Care Retailers
Hospital
Lodging
Merchandise Retail
Movie Theater
Parking
Telecommunications