[英]Athena View - Need to get a specific value from a column's original value
[英]Get max value by a group of column in SQL/Athena
我有以下列:
code note
1 10
2 8
1 9
3 5
3 4
如何獲得具有最大平均音符的代碼?
我的 output 應該是代碼 1,因為 AVG 是 9,5(代碼 1)、8(代碼 2)、4,5(代碼 3)
我在雅典娜的查詢:
select code from table group by code, avg(note) ORDER BY DESC limit 1
output 錯誤:
GROUP BY clause cannot contain aggregations, window functions or grouping operations
您的分組 function 必須在您的 SELECT 列列表中,而不是在您的 GROUP BY 子句中。
試試這個:
select code, avg(note) as avg_of_note
from table
group by code
order by avg_of_note desc
limit 1
另外:我不會親自命名列code
。 我可能擔心它會成為某些 SQL 方言中的保留字。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.