Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/390.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google bigquery 如何在Google大查询中展平行中的值_Google Bigquery_Flatten - Fatal编程技术网

Google bigquery 如何在Google大查询中展平行中的值

Google bigquery 如何在Google大查询中展平行中的值,google-bigquery,flatten,Google Bigquery,Flatten,伙计们 我在大查询中的数据有问题。我有一个像pic#1这样的数据集,我需要对我的用户进行排名,并将他们的排名记录分组到一个唯一的行中(如pic#2)。需要说明的是,我的排名列类型是int,而不是数组 可以处理这个w/bigquery吗?或者我需要将这个数据集传输到python并在那里进行转换吗 PIC#1原始数据集 PIC#2分组和格式化数据集 下面是BigQuery标准SQL的示例 #standardSQL WITH `project.dataset.table` AS ( SELECT

伙计们

我在大查询中的数据有问题。我有一个像pic#1这样的数据集,我需要对我的用户进行排名,并将他们的排名记录分组到一个唯一的行中(如pic#2)。需要说明的是,我的
排名
列类型是
int
,而不是
数组

可以处理这个w/bigquery吗?或者我需要将这个数据集传输到python并在那里进行转换吗

PIC#1原始数据集

PIC#2分组和格式化数据集


下面是BigQuery标准SQL的示例

#standardSQL
WITH `project.dataset.table` AS (
  SELECT 'a' user, 10 ranking UNION ALL
  SELECT 'b',  2 UNION ALL
  SELECT 'a', 12 UNION ALL
  SELECT 'a', 14 UNION ALL
  SELECT 'c', 22 UNION ALL
  SELECT 'd', 21 
)
SELECT 
  user, 
  MAX(ranking) AS ranking_max,
  STRING_AGG(CAST(ranking AS STRING)) ranking_list
FROM `project.dataset.table`
GROUP BY user   
结果

Row user    ranking_max ranking_list     
1   a       14          10,12,14     
2   b       2           2    
3   c       22          22   
4   d       21          21   
注意:如果您需要排序
ranking\u list
,您可以在
STRING\u AGG
中使用
ORDER BY
,如下所示

STRING_AGG(CAST(ranking AS STRING) ORDER BY ranking) ranking_list