分组计算时报错: All columns of a table must have the same length

请问下,我有一个这样的表,想 group by name,然后取value最大的一行,应该怎么操作?

我用下述语句会报错:

'select max(value) as max_value,other from t group by name => All columns of a table must have the same length.'


attachments-2023-06-jZgAJFeK6479b21ab96e8.png

请先 登录 后评论

1 个回答

veryOrdinary

group by 要求列字段必须是聚合计算,上述语句包含 other 字段是非聚合的,因此报错。

可以用 context by 替代 group by 做分组计算,可以参考下述脚本:

select * from t context by name csort value desc limit 1
请先 登录 后评论
  • 1 关注
  • 0 收藏,704 浏览
  • 提出于 2023-06-02 17:11

相似问题