sql获取值,其中一些值大于值,但不起作用

jq6vz3qz  于 2021-07-24  发布在  Java
关注(0)|答案(1)|浏览(248)

我有这个密码:

Select firstname, lastname, sum(quantity) as quantitySum
FROM Customer
JOIN "Order"
ON Customer.id = "Order".customerid
JOIN orderitem
ON "Order".id = orderitem.orderid
WHERE country = 'Germany'
GROUP BY firstname, lastname
HAVING quantitySum > 500
ORDER BY lastname

但这给了我一个错误。我想不通。感谢你的帮助!

jmp7cifd

jmp7cifd1#

Having 条款执行时间 group by 然后 select 所以你必须使用聚合函数 having 如下所示

Select firstname, lastname, sum(quantity) as quantitySum
FROM Customer
JOIN "Order"
ON Customer.id = "Order".customerid
JOIN orderitem
ON "Order".id = orderitem.orderid
WHERE country = 'Germany'
GROUP BY firstname, lastname
HAVING sum(quantity) > 500
ORDER BY lastname

相关问题