在 QoQ 中使用 sum 函数时出现意外错误

发布于 2025-01-15 20:59:57 字数 2086 浏览 0 评论 0原文

尝试运行以下代码时,

<cfquery name="Lev1CatTotal" dbtype="query">
    SELECT 
        SUM(AMOUNT) AS TOTAL
    FROM 
        ChartData
</cfquery>

这是生成的错误消息:

查询的查询运行时错误。聚合函数 [SUM(表达式)] 无法对 [JAVA_OBJECT] 类型的操作数进行运算。

当聚合较小的金额时,此代码可以正常工作。然而,这些是我汇总的表中的金额。这个特定的查询总计超过 $5.7B。

AMOUNTFISCAL_YRGOV_LEVEL1_CAT
979241575.142019 年服务费
97218277.182019 年向其他政府收取的费用
233197655.522019 年联邦援助
329567996.812019 年其他地方收入
86957092.752019 年其他非财产税
158997846.752019 年其他不动产税项目
371012673.892019 年其他来源
346575244.012019 年债务收益
1145011131.992019 年不动产税和评估
945308275.552019销售和使用税
921087680.042019国家援助
107357596.202019财产的使用和销售

为了继续前进,作为解决方法,我将其重新编码如下:

<cfset TOTAL = 0>
<cfloop query="ChartData">
    <cfset TOTAL = precisionEvaluate(TOTAL + AMOUNT)>
</cfloop>

使用 precisionEvaluate(),它将 TOTAL 转换为 BigDecimal 精度并避免错误。有人知道使用 sum() 函数将其转换为大十进制并避免使用此解决方法的 QoQ 解决方案吗?谢谢。

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.

AMOUNTFISCAL_YRGOV_LEVEL1_CAT
979241575.142019Charges for Services
97218277.182019Charges to Other Governments
233197655.522019Federal Aid
329567996.812019Other Local Revenues
86957092.752019Other Non-Property Taxes
158997846.752019Other Real Property Tax Items
371012673.892019Other Sources
346575244.012019Proceeds of Debt
1145011131.992019Real Property Taxes and Assessments
945308275.552019Sales and Use Tax
921087680.042019State Aid
107357596.202019Use 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浅暮の光 2025-01-22 20:59:57

非常感谢 @BernhardDöbler 让我了解 ChartData 的来源。由于这是继承的代码,我必须对此进行研究。事实证明 ChartData 是使用以下代码行创建的。

<cfset ChartData = QueryNew("FISCAL_YR, GOV_LEVEL1_CAT, AMOUNT")>

我注意到,原始编码器没有为其 QueryNew() 语句指定任何数据类型,因此我将代码行修改为

<cfset ChartData = QueryNew("FISCAL_YR, GOV_LEVEL1_CAT, AMOUNT", "VarChar, VarChar, Double")>

一旦将 Double 数据类型添加到AMOUNT 列,当我恢复到原始代码时它纠正了错误

<cfquery name="Lev1CatTotal" dbtype="query">
    SELECT 
        SUM(AMOUNT) AS TOTAL
    FROM 
        ChartData
</cfquery>

,并且我能够删除使用 执行聚合的解决方法代码。

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.

<cfset ChartData = QueryNew("FISCAL_YR, GOV_LEVEL1_CAT, AMOUNT")>

I noticed, the original coder didn't specify any data types for his QueryNew() statement, so I modified the line of code to

<cfset ChartData = QueryNew("FISCAL_YR, GOV_LEVEL1_CAT, AMOUNT", "VarChar, VarChar, Double")>

Once I added the Double data type to the AMOUNT column, it corrected the error when I restored back to the original code of

<cfquery name="Lev1CatTotal" dbtype="query">
    SELECT 
        SUM(AMOUNT) AS TOTAL
    FROM 
        ChartData
</cfquery>

and I was able to remove my workaround code which performed the aggregation using a <cfloop>.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文