作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这是我关于堆栈溢出的第一篇文章。每次我需要这里的东西时,其他人已经问过这个问题。我找不到任何类似这样的问题,所以我想发一个新帖子。
我的 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/
我是一名优秀的程序员,十分优秀!