MySQL Error number: 3029; Symbol: ER_AGGREGATE_ORDER_NON_AGG_QUERY; SQLSTATE: HY000 报错 故障修复 远程处理

文档解释

Error number: 3029; Symbol: ER_AGGREGATE_ORDER_NON_AGG_QUERY; SQLSTATE: HY000

Message: Expression #%u of ORDER BY contains aggregate function and applies to the result of a non-aggregated query

(至少一种)

Error 3029 (HY000): ER_AGGREGATE_ORDER_NON_AGG_QUERY

错误说明:

此错误产生当在查询中使用ORDER BY 时,与非聚合列不兼容。

常见案例

如果只有一个非聚合的列,且使用Order By子句用它排序,则可能会收到此错误消息:

Erro 3029 (HY000): ER_AGGREGATE_ORDER_NON_AGG_QUERY

下面的查询会生成上述错误消息:

SELECT category

FROM products

ORDER BY sales;

解决方法:

1.使用聚合函数使查询满足ORDER BY要求:

SELECT category, MAX(sales)

FROM products

GROUP BY category

ORDER BY sales;

2.将不需要排序的非聚合函数去掉:

SELECT category

FROM products;


数据运维技术 » MySQL Error number: 3029; Symbol: ER_AGGREGATE_ORDER_NON_AGG_QUERY; SQLSTATE: HY000 报错 故障修复 远程处理