gpt4 book ai didi

google-bigquery - 错误 : SELECT list expression references column created_utc which is neither grouped nor aggregated at [2:49]

转载 作者:行者123 更新时间:2023-12-04 20:45:01 27 4
gpt4 key购买 nike

我有一张 table :t

我的目标:仅提取表中得分最高的“id”,并按week_number 对其进行分组。

询问:

SELECT id, 
CAST(EXTRACT(WEEK FROM TIMESTAMP_SECONDS(created_utc)) AS STRING) AS week_number,
MAX(score) AS highest_score
FROM t
WHERE body='r/twinpeaks'
GROUP BY id;

我收到此错误:
错误:SELECT 列表表达式引用了在 [2:49] 处既未分组也未聚合的列 created_utc

我尝试这样做:
SELECT id, 
CAST(EXTRACT(WEEK FROM TIMESTAMP_SECONDS(created_utc)) AS STRING) AS week_number,
MAX(score) AS highest_score
FROM t
WHERE body='r/twinpeaks'
GROUP BY week_number, id;

但这就是我得到的:
Row  id            week_number  highest_score    
1 dmkb6sv 36 1
2 dn1cd2s 37 2
3 dn43h1k 38 16
4 dn3xf18 38 1
5 dn7i1ko 38 1
6 dnpr9b1 39 1

我要这个:
Row  id            week_number  highest_score    
1 dmkb6sv 36 1
2 dn1cd2s 37 2
3 dn43h1k 38 16
6 dnpr9b1 39 1

最佳答案

下面是 BigQuery 标准 SQL



#standardSQL
SELECT
EXTRACT(WEEK FROM TIMESTAMP_SECONDS(created_utc)) AS week_number,
ARRAY_AGG(id ORDER BY score DESC LIMIT 1)[OFFSET(0)] id,
ARRAY_AGG(score ORDER BY score DESC LIMIT 1)[OFFSET(0)] highest_score
FROM `project.dataset.table`
WHERE body = 'r/twinpeaks'
GROUP BY week_number
ORDER BY week_number

关于google-bigquery - 错误 : SELECT list expression references column created_utc which is neither grouped nor aggregated at [2:49],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49041489/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com