【发布时间】:2021-11-18 13:20:29
【问题描述】:
首先,很抱歉提出这个问题,因为有很多类似的问题。但我无法根据这些问题和答案更新我的所有行。
所以我有一个关于这个thread的后续问题
新选择的数据——same_location_count、same_location_store,我希望这些数据在同一张表上更新。就像,我希望它也被更新,而不仅仅是选择。
从这里:
store_name | latitude | longitude | store_id | same_location_count | same_location_store_id
SR Restaurant and Cafe | -41.575449 | 147.16824 | 1112 | 0 | null
Big Bite Burgers | -41.575449 | 147.16824 | 1113 | 0 | null
Amigos | -41.575449 | 147.16824 | 1114 | 0 | null
Domino's | -38.33983 | 143.58384 | 1115 | 0 | null
到这里:
store_name | latitude | longitude | store_id | same_location_count | same_location_store_id
SR Restaurant and Cafe | -41.575449 | 147.16824 | 1112 | 2 | 1113:1114
Big Bite Burgers | -41.575449 | 147.16824 | 1113 | 2 | 1112:1114
Amigos | -41.575449 | 147.16824 | 1114 | 2 | 1112:1113
Domino's | -38.33983 | 143.58384 | 1115 | 0 | null
这是适合我的选择语句:
SELECT
*,
(COUNT(id) OVER (PARTITION BY lat, long))-1 AS same_location_count,
REPLACE( STRING_AGG(CONCAT(id,':'),'') OVER (PARTITION BY lat, long), CONCAT(id,':'), '') AS same_location_store_id
FROM
test
现在,进入下一步,我将如何使用这些选定的数据更新表格?
【问题讨论】:
-
看看在更新查询中使用连接。 stackoverflow.com/questions/47373774/… 所以本质上你加入你的查询并使用它的值来更新你的键的集合语句中的更新
标签: sql google-bigquery