gpt4 book ai didi

mysql - SQL 给出错误,即使看起来是正确的

转载 作者:行者123 更新时间:2023-11-29 09:45:26 24 4
gpt4 key购买 nike

报错,我试图看看哪里出了问题,但无济于事。请帮忙

 SELECT UserId, AVG(Total) AS AvgOrderTotal
FROM Invoices
HAVING COUNT(OrderId) >= 1

最佳答案

您缺少GROUP BY:

SELECT UserId, AVG(Total) AS AvgOrderTotal
FROM Invoices
GROUP BY UserId
HAVING COUNT(OrderId) >= 1

假设 OrderId 永远不会 NULL,则 HAVING 是多余的,所以也许这就足够了:

SELECT UserId, AVG(Total) AS AvgOrderTotal
FROM Invoices
GROUP BY UserId;

关于mysql - SQL 给出错误,即使看起来是正确的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55775065/

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