Teradata 3504/3627 问题
我在涉及以下列的特定查询时一直遇到同样的问题:
CAST((COALESCE(price, 0.000000)) AS DECIMAL(18,6)) * quantity amount (TITLE 'Amount')
如果我不在组中提及它,它会喷出错误 3504,如果我这样做,则会喷出错误 3627。
关于如何正确构造这一部分的任何想法查询的?
编辑:如果您需要更多信息,请询问:)
I keep having the same issue revolving a particular query which has the following column:
CAST((COALESCE(price, 0.000000)) AS DECIMAL(18,6)) * quantity amount (TITLE 'Amount')
If I don't mention it in the group by it spews error 3504, if I do it spews back error 3627.
Any idea on how to properly structure this part of the query?
edit: if you need more info, please ask away :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我相信您在这里遇到了多个问题(没有更多代码很难说)。
当该列不是 GROUP BY 子句的一部分时,会出现 3504,因为所有不属于 GROUP BY 的列都必须是“聚合”函数(例如 SUM、MAX、MIN、AVG 等)。当您将其包含在 GROUP BY 中时,此列现在就可以了。
但是,我的猜测是您的 SELECTion 列表中还有一个 COUNT(DISTINCT(x)) 。当同时使用 GROUP BY 时,不能在查询的 SELECT、ORDER BY 或 HAVING 子句中使用 DISTINCT 函数。我怀疑如果你删除 DISTINCT,留下 COUNT(*),这会起作用。
顺便说一句,我不确定您是否想按此处提到的列进行分组。根据财务金额进行分组是不寻常的。例如,此列使用 SUM 函数进行聚合会更常见。否则,您可能需要重新考虑为什么要使用 GROUP BY(因为按“金额”分组会给您带来奇怪的结果,本质上为返回的每一行提供一行,除了 GROUP BY 列和“金额”之外)是相同的,它将折叠成一行,这意味着您将得到不一致的结果)。
希望这有帮助。
I believe you are experiencing multiple problems here (it's hard to say without more code).
The 3504 occurs when this column is not part of the GROUP BY clause because all columns that aren't part of the GROUP BY must be "aggregate" functions (eg. SUM, MAX, MIN, AVG, etc). When you do include it in the GROUP BY, this column is now fine.
However, my guess is that you also have a COUNT(DISTINCT(x)) in you SELECTion list. You can't use the DISTINCT function in the SELECT, ORDER BY, or HAVING clause of a query when also using a GROUP BY. I suspect if you remove the DISTINCT, leaving you with COUNT(*), this will work.
As an aside, I'm not sure you want to be grouping by the column you mention here. It's unusual to group on a financial amount. It would be more common for this column to be aggregated with a SUM function for instance. Or otherwise you may want to reconsider why you're using a GROUP BY (as grouping by the "amount" will give you odd results, essentially giving you one row for each row returned, except where the GROUP BY columns and the "amount" are the same, where it will collapse it down to a single row, meaning you will get inconsistent results).
Hope this helps.