在 QoQ 中使用 sum 函数时出现意外错误
尝试运行以下代码时,
<cfquery name="Lev1CatTotal" dbtype="query">
SELECT
SUM(AMOUNT) AS TOTAL
FROM
ChartData
</cfquery>
这是生成的错误消息:
查询的查询运行时错误。聚合函数 [SUM(表达式)] 无法对 [JAVA_OBJECT] 类型的操作数进行运算。
当聚合较小的金额时,此代码可以正常工作。然而,这些是我汇总的表中的金额。这个特定的查询总计超过 $5.7B。
AMOUNT | FISCAL_YR | GOV_LEVEL1_CAT |
---|---|---|
979241575.14 | 2019 年 | 服务费 |
97218277.18 | 2019 年 | 向其他政府收取的费用 |
233197655.52 | 2019 年 | 联邦援助 |
329567996.81 | 2019 年 | 其他地方收入 |
86957092.75 | 2019 年 | 其他非财产税 |
158997846.75 | 2019 年 | 其他不动产税项目 |
371012673.89 | 2019 年 | 其他来源 |
346575244.01 | 2019 年 | 债务收益 |
1145011131.99 | 2019 年 | 不动产税和评估 |
945308275.55 | 2019 | 销售和使用税 |
921087680.04 | 2019 | 国家援助 |
107357596.20 | 2019 | 财产的使用和销售 |
为了继续前进,作为解决方法,我将其重新编码如下:
<cfset TOTAL = 0>
<cfloop query="ChartData">
<cfset TOTAL = precisionEvaluate(TOTAL + AMOUNT)>
</cfloop>
While attempting to run the following code
<cfquery name="Lev1CatTotal" dbtype="query">
SELECT
SUM(AMOUNT) AS TOTAL
FROM
ChartData
</cfquery>
This is the error message that's generated:
Query Of Queries runtime error. The aggregate function [SUM(expression)] cannot operate on an operand of type [JAVA_OBJECT]
This code works fine when aggregating smaller amounts. However, these are the amount in the table I'm aggregating. This particular query sums to over $5.7B.
AMOUNT | FISCAL_YR | GOV_LEVEL1_CAT |
---|---|---|
979241575.14 | 2019 | Charges for Services |
97218277.18 | 2019 | Charges to Other Governments |
233197655.52 | 2019 | Federal Aid |
329567996.81 | 2019 | Other Local Revenues |
86957092.75 | 2019 | Other Non-Property Taxes |
158997846.75 | 2019 | Other Real Property Tax Items |
371012673.89 | 2019 | Other Sources |
346575244.01 | 2019 | Proceeds of Debt |
1145011131.99 | 2019 | Real Property Taxes and Assessments |
945308275.55 | 2019 | Sales and Use Tax |
921087680.04 | 2019 | State Aid |
107357596.20 | 2019 | Use and Sale of Property |
Just to move forward, as a workaround, I recoded this as follows:
<cfset TOTAL = 0>
<cfloop query="ChartData">
<cfset TOTAL = precisionEvaluate(TOTAL + AMOUNT)>
</cfloop>
Using precisionEvaluate()
, it casts the TOTAL
to BigDecimal
precision and avoids the error. Does someone know of a QoQ solution using the sum()
function to cast this to a big decimal and avoid using this workaround? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
非常感谢 @BernhardDöbler 让我了解 ChartData 的来源。由于这是继承的代码,我必须对此进行研究。事实证明 ChartData 是使用以下代码行创建的。
我注意到,原始编码器没有为其
QueryNew()
语句指定任何数据类型,因此我将代码行修改为一旦将
Double
数据类型添加到AMOUNT
列,当我恢复到原始代码时它纠正了错误,并且我能够删除使用
执行聚合的解决方法代码。Big thanks to @BernhardDöbler for getting me to look into where ChartData comes from. Since this was inherited code, I had to look into this. It turned out that ChartData was created with the following line of code.
I noticed, the original coder didn't specify any data types for his
QueryNew()
statement, so I modified the line of code toOnce I added the
Double
data type to theAMOUNT
column, it corrected the error when I restored back to the original code ofand I was able to remove my workaround code which performed the aggregation using a
<cfloop>
.