Jasper reports 如何按日期筛选表(交叉表)中的数据

Jasper reports 如何按日期筛选表(交叉表)中的数据,jasper-reports,crosstab,Jasper Reports,Crosstab,在使用iReport为此布局创建报告时,我需要一些帮助。我可以使用交叉表创建记录,但它会创建重复的记录 Male Female 日期 总数 质疑 SELECT table1.`gender` AS table1_gender, registration_details.`date_reg` AS registration_details_date_reg FROM `table1` table1

在使用iReport为此布局创建报告时,我需要一些帮助。我可以使用交叉表创建记录,但它会创建重复的记录

                   Male                      Female
日期

总数

质疑

SELECT table1.`gender` AS table1_gender,
     registration_details.`date_reg` AS registration_details_date_reg
FROM
     `table1` table1 INNER JOIN `date_reg` date_reg ON table1.`candidate_id` = registration_details.`candidate_id`
在哪里 表1显示了性别(候选人编号:pk) 注册详细信息中存在日期注册

jrxml:


目前显示所有记录,需要建议/帮助创建报告 用户可以通过提供日期来获取记录

而且它的打印单记录多次


我将感谢任何帮助

要按日期筛选数据,可以添加paramater(java.lang.String或java.util.date)类型并在查询中使用它

例如:


...
...
选择。。。。从…起哪里有$P!{dqlDateFilter}

您应该为您的案例编写正确的日期筛选器。

您是否检查了查询?它是否返回重复记录?
<?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="report12" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
    <style name="Crosstab Data Text" hAlign="Center"/>
    <style name="table">
        <box>
            <pen lineWidth="1.0" lineColor="#000000"/>
        </box>
    </style>
    <style name="table_TH" mode="Opaque" backcolor="#F0F8FF">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </style>
    <style name="table_CH" mode="Opaque" backcolor="#BFE1FF">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </style>
    <style name="table_TD" mode="Opaque" backcolor="#FFFFFF">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </style>
    <style name="table 1">
        <box>
            <pen lineWidth="1.0" lineColor="#000000"/>
        </box>
    </style>
    <style name="table 1_TH" mode="Opaque" backcolor="#F0F8FF">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </style>
    <style name="table 1_CH" mode="Opaque" backcolor="#BFE1FF">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </style>
    <style name="table 1_TD" mode="Opaque" backcolor="#FFFFFF">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </style>
    <subDataset name="New Dataset 1">
        <queryString language="SQL">
            <![CDATA[SELECT
     table1.`gender` AS table1_gender,
    registration_details.`date_reg` AS registration_details_date_reg
FROM
 `table1` table1 INNER JOIN `date_reg` date_reg ON table1.`candidate_id` = registration_details.`candidate_id`]]>
        </queryString>
        <field name="table1_gender" class="java.lang.String"/>
        <field name="registration_details_date_reg" class="java.sql.Date"/>
    </subDataset>
    <subDataset name="Table Dataset 1"/>
    <queryString language="SQL">
        <![CDATA[SELECT
     table1.`gender` AS table1_gender,
     registration_details.`date_reg` AS registration_details_date_reg
FROM
     `table1` table1 INNER JOIN `date_reg` date_reg ON table1.`candidate_id` = registration_details.`candidate_id`]]>
    </queryString>
    <field name="table1_gender" class="java.lang.String"/>
    <field name="date_reg" class="java.sql.Date"/>
    <detail>
        <band height="125" splitType="Stretch">
            <crosstab>
                <reportElement x="0" y="0" width="555" height="125"/>
                <crosstabDataset>
                    <dataset>
                        <datasetRun subDataset="New Dataset 1">
                            <connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
                        </datasetRun>
                    </dataset>
                </crosstabDataset>
                <rowGroup name="date_reg" width="70" totalPosition="End">
                    <bucket>
                        <bucketExpression class="java.lang.String"><![CDATA[(new SimpleDateFormat("yyyy-MM-dd")).format($F{date_reg})]]></bucketExpression>
                    </bucket>
                    <crosstabRowHeader>
                        <cellContents backcolor="#F0F8FF" mode="Opaque">
                            <box>
                                <pen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                            </box>
                            <textField>
                                <reportElement style="Crosstab Data Text" x="0" y="0" width="70" height="25"/>
                                <textElement/>
                                <textFieldExpression class="java.lang.String"><![CDATA[$V{date_reg}]]></textFieldExpression>
                            </textField>
                        </cellContents>
                    </crosstabRowHeader>
                    <crosstabTotalRowHeader>
                        <cellContents backcolor="#BFE1FF" mode="Opaque">
                            <box>
                                <pen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                            </box>
                            <staticText>
                                <reportElement x="0" y="0" width="70" height="25"/>
                                <textElement textAlignment="Center" verticalAlignment="Middle"/>
                                <text><![CDATA[Total date_reg]]></text>
                            </staticText>
                        </cellContents>
                    </crosstabTotalRowHeader>
                </rowGroup>
                <columnGroup name="table1_gender" height="30" totalPosition="End">
                    <bucket>
                        <bucketExpression class="java.lang.String"><![CDATA[$F{table1_gender}]]></bucketExpression>
                    </bucket>
                    <crosstabColumnHeader>
                        <cellContents backcolor="#F0F8FF" mode="Opaque">
                            <box>
                                <pen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                            </box>
                            <textField>
                                <reportElement style="Crosstab Data Text" x="0" y="0" width="50" height="30"/>
                                <textElement/>
                                <textFieldExpression class="java.lang.String"><![CDATA[$V{student_gender}]]></textFieldExpression>
                            </textField>
                        </cellContents>
                    </crosstabColumnHeader>
                    <crosstabTotalColumnHeader>
                        <cellContents backcolor="#BFE1FF" mode="Opaque">
                            <box>
                                <pen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                            </box>
                            <staticText>
                                <reportElement x="0" y="0" width="50" height="30"/>
                                <textElement textAlignment="Center" verticalAlignment="Middle"/>
                                <text><![CDATA[Total student_gender]]></text>
                            </staticText>
                        </cellContents>
                    </crosstabTotalColumnHeader>
                </columnGroup>
                <measure name="table1_genderMeasure" class="java.lang.Integer" calculation="Count">
                    <measureExpression><![CDATA[$F{table1_gender}]]></measureExpression>
                </measure>
                <crosstabCell width="50" height="25">
                    <cellContents>
                        <box>
                            <pen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                        </box>
                        <textField>
                            <reportElement style="Crosstab Data Text" x="0" y="0" width="50" height="25"/>
                            <textElement/>
                            <textFieldExpression class="java.lang.Integer"><![CDATA[$V{table1_genderMeasure}]]></textFieldExpression>
                        </textField>
                    </cellContents>
                </crosstabCell>
                <crosstabCell height="25" rowTotalGroup="date_reg">
                    <cellContents backcolor="#BFE1FF" mode="Opaque">
                        <box>
                            <pen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                        </box>
                        <textField>
                            <reportElement style="Crosstab Data Text" x="0" y="0" width="50" height="25"/>
                            <textElement/>
                            <textFieldExpression class="java.lang.Integer"><![CDATA[$V{table1_genderMeasure}]]></textFieldExpression>
                        </textField>
                    </cellContents>
                </crosstabCell>
                <crosstabCell width="50" columnTotalGroup="student_gender">
                    <cellContents backcolor="#BFE1FF" mode="Opaque">
                        <box>
                            <pen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                        </box>
                        <textField>
                            <reportElement style="Crosstab Data Text" x="0" y="0" width="50" height="25"/>
                            <textElement/>
                            <textFieldExpression class="java.lang.Integer"><![CDATA[$V{table1_genderMeasure}]]></textFieldExpression>
                        </textField>
                    </cellContents>
                </crosstabCell>
                <crosstabCell rowTotalGroup="date_reg" columnTotalGroup="table1_gender">
                    <cellContents backcolor="#BFE1FF" mode="Opaque">
                        <box>
                            <pen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                        </box>
                        <textField>
                            <reportElement style="Crosstab Data Text" x="0" y="0" width="50" height="25"/>
                            <textElement/>
                            <textFieldExpression class="java.lang.Integer"><![CDATA[$V{table1_genderMeasure}]]></textFieldExpression>
                        </textField>
                    </cellContents>
                </crosstabCell>
            </crosstab>
        </band>
    </detail>
</jasperReport>