我不知道如何标题这个问题,我知道它只是一个简单而愚蠢的逻辑需要整理出来,但我可以解释我需要什么。我有一个jasper报告脚本和查询,其中我需要根据从下面的查询收集的值进行简单的计算
SELECT TOTAL, PARTIAL FROM PRICE WHERE TOTAL > 0
现在我需要将此值计算为jasper report script
中的以下表达式VAR CALC += TOTAL + (PARTIAL) //as partial can be a -ve or +ve value
目前发生的事情是,我没有找到办法做到这一点,每当我为变量指定TOTAL
的值并尝试使用它时,它总会得到'来自Query的值并计算,而我需要它只在那里一次,然后对它进行计算。为此,我尝试使用calculation="First"
但是它也一直给出第一个值并继续。我希望我能很好地解决我的问题,请帮助
修改
QUERY
SELECT RECEIPTS.DATENEW AS DATE,
TICKETS.TICKETID AS TICKETID,
PAYMENTS.PAYMENT AS PAYMENT,
PAYMENTS.METHOD AS METHOD,
PAYMENTS.TOTAL AS TOTAL,
CUSTOMERS.NAME AS NAME,
(SELECT SUM(P.TOTAL) FROM PAYMENTS AS P
INNER JOIN RECEIPTS AS R ON P.RECEIPT = R.ID
INNER JOIN TICKETS AS T ON R.ID = T.ID
INNER JOIN CUSTOMERS AS C ON T.CUSTOMER = C.ID
WHERE C.ID = CUSTOMERS.ID and P.PAYMENT IN ('debt','debtpaid', 'advance', 'cashrefund')) AS CTOTAL
FROM RECEIPTS
INNER JOIN TICKETS ON RECEIPTS.ID = TICKETS.ID
INNER JOIN PAYMENTS ON RECEIPTS.ID = PAYMENTS.RECEIPT
INNER JOIN CUSTOMERS ON TICKETS.CUSTOMER = CUSTOMERS.ID
WHERE
PAYMENTS.PAYMENT IN ('debt', 'debtpaid', 'advance', 'cashrefund')
....
....
WHERE -TOTAL > 0
可变
<variable name="DUES" class="java.lang.Double" resetGroup="Customer" resetType="Group" calculation="Nothing">
<variableExpression><![CDATA[$F{CTOTAL} + $F{TOTAL}]]></variableExpression>
<initialValueExpression><![CDATA[new Double(0.0)]]></initialValueExpression>
</variable>
输出
答案 0 :(得分:0)
您可以在SQL语句中定义变量本身,如下所示: -
SELECT SUM(@csum := @csum + TOTAL+PARTIAL)
FROM (SELECT TOTAL, PARTIAL,@csum := 0
FROM PRICE WHERE TOTAL > 0
) a;