gpt4 book ai didi

SQL 错误 42803 : I shouldn't be getting this error, 怎么回事?

转载 作者:行者123 更新时间:2023-11-29 13:11:58 25 4
gpt4 key购买 nike

这是我关于堆栈溢出的第一篇文章。每次我需要这里的东西时,其他人已经问过这个问题。我找不到任何类似这样的问题,所以我想发一个新帖子。

我的 SQL 查询有点问题,错误代码对我来说意义不大。查询如下:

SELECT customer.account as "Account", customer.name as "Customer Name", sum(slpayment.payment_amount) as "Payment Amount", slpayment.reference, max(date(slpayment.payment_date)) as "Payment Date",  
CASE WHEN customer.userchk1 = '1' then 'B' else ' Y' END as type
FROM customer
INNER JOIN slpayment ON customer.company = slpayment.company and
customer.account = slpayment.account
WHERE slpayment.sales_period='11'

此查询标记 SQL 错误 42803:“错误:列“customer.account”必须出现在 GROUP BY 子句中或用于聚合函数中”

我很熟悉这个错误,并且已经在其他查询中解决了它。但是,我不明白的是为什么会出现此错误。有问题的查询在函数的任何地方都没有 GROUP BY 子句。我看了一下其他人,他们在这里就堆栈溢出提出了类似的问题,但他们所有的查询都包含 GROUP BY,因此他们得到错误的原因是有道理的。我只是不知道为什么我会在这里遇到麻烦。

提前感谢您的关注!

最佳答案

您需要添加group by 子句并应用除聚合列之外的所有列

SELECT customer.account as "Account", customer.name as "Customer Name", sum(slpayment.payment_amount) as "Payment Amount", slpayment.reference, max(date(slpayment.payment_date)) as "Payment Date", CASE WHEN customer.userchk1 = '1' then 'B' else ' Y' END as type 
FROM customer INNER JOIN slpayment
ON customer.company = slpayment.company and customer.account = slpayment.account
WHERE slpayment.sales_period='11'
group by customer.account , customer.name ,slpayment.reference,customer.userchk1

关于SQL 错误 42803 : I shouldn't be getting this error, 怎么回事?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53629839/

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