sql [BigQuery - Facebook产品目录]查询para obtenerelcatálogodeproductos de Kichink。 #facebook #bigqu

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sql [BigQuery - Facebook产品目录]查询para obtenerelcatálogodeproductos de Kichink。 #facebook #bigqu相关的知识,希望对你有一定的参考价值。

SELECT
  it.item_id AS id,
  CASE
    WHEN (it.name_spanish is null OR it.name_spanish = "" OR it.name_spanish = ".") THEN STRING(it.item_id)
    ELSE LOWER(REPLACE(it.name_spanish, '"', ''))
  END title,
  CASE
    WHEN (it.description_spanish is null OR it.description_spanish = "" OR it.description_spanish = ".") THEN STRING(it.item_id)
    ELSE LOWER(REPLACE(it.description_spanish, '"', ''))
  END description,
  CASE
    WHEN it.units_available = 0 THEN 'out of stock'
    ELSE 'in stock'
  END availability,
  "new" AS condition,
  CONCAT(STRING(it.price), " MXN") AS price,
  CONCAT("https://www.kichink.com/buy/", STRING(it.item_id), "/") AS link,
  sto.name_spanish AS brand,
  img.bordered AS image_link,
  catgoo.level_1 as google_product_category,
  o0.store_gmv as custom_label_0,
  o1.store_age as custom_label_1
FROM
  [kch-data-warehouse-170114:Kichink_DWH.dim_items] AS it
JOIN (
  SELECT
    store_id,
    name_spanish,
    is_active
  FROM
    [kch-data-warehouse-170114:Kichink_DWH.dim_stores]) AS sto
ON
  sto.store_id = it.store_id
JOIN (
  SELECT
    INTEGER(item_id) AS item_id,
    min(bordered) as bordered,
    min(object_order) as object_order,
    type
  FROM
    [kch-data-warehouse-170114:Kichink_DWH.view_item_image_log]
  group by item_id, type) AS img
ON
  img.item_id = it.item_id
LEFT JOIN
  [kch-data-warehouse-170114:kategorias.item_topic_30] AS itcat
ON
  itcat.int64_field_0 = it.item_id

LEFT JOIN
  [kch-data-warehouse-170114:kategorias.categories_topic_30] AS catid on catid.topic_id = itcat.V1
  
LEFT JOIN
  [kch-data-warehouse-170114:kategorias.categories_google] AS catgoo on catgoo.category_id = catid.category_id
  
LEFT JOIN
  (
  select store_id,
         CASE
           WHEN sum(total_price) > 400000 THEN '1. t1'
           WHEN sum(total_price) BETWEEN 200001 AND 400000 THEN '2. t2'
           WHEN sum(total_price) BETWEEN 100001 AND 200000 THEN '3. t3'
           WHEN sum(total_price) BETWEEN 40001 AND 100000 THEN '4. t4'
		   WHEN sum(total_price) <= 40000 THEN '5. t5'
       END store_gmv
  from [kch-data-warehouse-170114:Kichink_DWH.fact_orders]
  where date(created_at) between DATE(DATE_ADD(CURRENT_TIMESTAMP(), -28, "DAY")) and CURRENT_DATE()
  group by store_id
  ) as o0 on o0.store_id = it.store_id
  
LEFT JOIN (
  select store_id,
         CASE
	       WHEN DATEDIFF(CURRENT_TIMESTAMP(), min(created_at)) < 92 then '0. new'
	       WHEN DATEDIFF(CURRENT_TIMESTAMP(), min(created_at)) between 92 and 183 then '1. baby'
	       WHEN DATEDIFF(CURRENT_TIMESTAMP(), min(created_at)) between 184 and 365 then '2. teen'
	       WHEN DATEDIFF(CURRENT_TIMESTAMP(), min(created_at)) between 366 and 730 then '3. adult'
	       WHEN DATEDIFF(CURRENT_TIMESTAMP(), min(created_at)) > 730 then '4. senior'
	       END store_age
  from [kch-data-warehouse-170114:Kichink_DWH.fact_orders]
  group by store_id
) o1 on o1.store_id = it.store_id
  
WHERE
  (it.is_active = 1
    AND it.is_deleted = 0)
  AND sto.is_active = 1
  AND img.type = 'img_bordered'
GROUP BY
  id,
  title,
  description,
  availability,
  condition,
  price,
  link,
  brand,
  image_link,
  google_product_category,
  custom_label_0,
  custom_label_1
ORDER BY
  id asc

以上是关于sql [BigQuery - Facebook产品目录]查询para obtenerelcatálogodeproductos de Kichink。 #facebook #bigqu的主要内容,如果未能解决你的问题,请参考以下文章

如何使用 Bigquery 连接 GCP SQL 实例?

BigQuery:如何在 C# 中启用标准 SQL

BigQuery 标准 SQL 中的 JSON_EXTRACT?

寻找 BigQuery 标准 SQL 教程、示例、书籍的新手,

谷歌 bigquery - 更新 sql?

Google 标准 SQL UDF - 写入 BigQuery