1
我需要一些幫助來使用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(candidate_id:PK) date_reg存在於registration_details
的JRXML:
<?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>
目前其展示的所有記錄,需要創建報表 當用戶將能夠通過提供最新獲取記錄的建議/幫助。
也是其單打印多次記錄。
我將不勝感激任何幫助。
你檢查了你的查詢嗎?它是否會返回重複的記錄? –