2

我正在尝试使用以下信息计算报告的值:

主题组有多个事件组,每个事件都有一个值为 1 或 0 的字段。我试图弄清楚如何计算至少有一个值为 1 的事件组的主题组的数量。

我曾尝试拆分为多个变量,但似乎无法正确计算或重置。我可以返回所有事件的计数和所有值为 1 的事件的总和。

我的数据表明 5 个事件的值为 1,但我需要返回主题数,即 4。任何帮助将不胜感激。

4

1 回答 1

0

试试这个 - 这是 2 个组和一个详细值。我们获取内部组中详细值的总和,然后计算该内部组的总和 > 0 的值。当您将其放入 iReport 时,请检查重置类型/组和增量类型/组。也有一些示例数据。

<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="report3" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="9c7e3951-509f-4aa7-8f30-bc6196708d3d">
    <property name="ireport.zoom" value="1.0"/>
    <property name="ireport.x" value="0"/>
    <property name="ireport.y" value="0"/>
    <queryString>
        <![CDATA[SELECT 'I1' AS GROUP_1,
  'J1' AS GROUP_2,
  0 AS DETAIL_VALUE
FROM DUAL

UNION

SELECT 'I1' AS GROUP_1,
  'J2' AS GROUP_2,
  1 AS DETAIL_VALUE
FROM DUAL

UNION

SELECT 'I2' AS GROUP_1,
  'J1' AS GROUP_2,
  1 AS DETAIL_VALUE
FROM DUAL

UNION

SELECT 'I2' AS GROUP_1,
  'J2' AS GROUP_2,
  1 AS DETAIL_VALUE
  FROM DUAL

UNION

SELECT 'I2' AS GROUP_1,
  'J3' AS GROUP_2,
  1 AS DETAIL_VALUE
FROM DUAL

UNION

SELECT 'I3' AS GROUP_1,
  'J1' AS GROUP_2,
  0 AS DETAIL_VALUE
FROM DUAL

UNION

SELECT 'I3' AS GROUP_1,
  'J2' AS GROUP_2,
  0 AS DETAIL_VALUE
FROM DUAL]]>
    </queryString>
    <field name="GROUP_1" class="java.lang.String"/>
    <field name="GROUP_2" class="java.lang.String"/>
    <field name="DETAIL_VALUE" class="java.math.BigDecimal"/>
    <variable name="GROUP_2_SUM" class="java.math.BigDecimal" resetType="Group" resetGroup="GROUP_1" calculation="Sum">
        <variableExpression><![CDATA[$F{DETAIL_VALUE} == 1 ? 1 : 0]]></variableExpression>
    </variable>
    <variable name="GROUP_1_TALLY" class="java.math.BigDecimal" resetType="Group" resetGroup="GROUP_1" calculation="Count">
        <variableExpression><![CDATA[$V{GROUP_2_SUM} > 0 ? 1 : 0]]></variableExpression>
    </variable>
    <group name="GROUP_1">
        <groupExpression><![CDATA[$F{GROUP_1}]]></groupExpression>
        <groupHeader>
            <band height="25">
                <textField>
                    <reportElement uuid="5216d0ad-f2f0-43ae-b344-95019a7a99eb" x="0" y="0" width="100" height="20"/>
                    <textElement/>
                    <textFieldExpression><![CDATA[$F{GROUP_1}]]></textFieldExpression>
                </textField>
            </band>
        </groupHeader>
        <groupFooter>
            <band height="25">
                <textField>
                    <reportElement uuid="e4ac638c-f609-45b1-94ba-27d9f5d9c28c" x="455" y="0" width="100" height="20"/>
                    <textElement/>
                    <textFieldExpression><![CDATA[$V{GROUP_2_SUM}]]></textFieldExpression>
                </textField>
            </band>
        </groupFooter>
    </group>
    <group name="GROUP_2">
        <groupExpression><![CDATA[$F{GROUP_2}]]></groupExpression>
        <groupHeader>
            <band height="25">
                <textField>
                    <reportElement uuid="437a9d72-5916-493a-b1f1-c582e2ad0f64" x="20" y="0" width="100" height="20"/>
                    <textElement/>
                    <textFieldExpression><![CDATA[$F{GROUP_2}]]></textFieldExpression>
                </textField>
            </band>
        </groupHeader>
        <groupFooter>
            <band height="25"/>
        </groupFooter>
    </group>
    <background>
        <band splitType="Stretch"/>
    </background>
    <detail>
        <band height="25" splitType="Stretch">
            <textField>
                <reportElement uuid="21cd5fb1-94a1-448e-ab53-0fa846fedee5" x="40" y="0" width="100" height="20"/>
                <textElement/>
                <textFieldExpression><![CDATA[$F{DETAIL_VALUE}]]></textFieldExpression>
            </textField>
        </band>
    </detail>
    <summary>
        <band height="42" splitType="Stretch">
            <textField>
                <reportElement uuid="624d0f87-ce9a-44d6-8e2c-be0ec7e65da2" x="455" y="0" width="100" height="20"/>
                <textElement/>
                <textFieldExpression><![CDATA[$V{GROUP_1_TALLY}]]></textFieldExpression>
            </textField>
        </band>
    </summary>
</jasperReport>
于 2012-07-25T15:34:02.703 回答