我在子报表中有以下SQL查询:
select ifnull(sum (commissionDocument.netto), 0) as commissionCreditNoteNetValue,
( select ifnull (sum (commissionDocument.netto ), 0)
from tckopf as commissionDocument
where commissionDocument.referenzid = $P{document_id}
and commissionDocument.btyp = 7) as commissionInvoiceNetValue
from tckopf as commissionDocument
where commissionDocument.referenzid = $P{document_id}
and commissionDocument.btyp = 8
问题是,如果where
子句:
where commissionDocument.referenzid = $P{document_id}
and commissionDocument.btyp = 8
不匹配,其他where
子句匹配。
where commissionDocument.referenzid = $P{document_id}
and commissionDocument.btyp = 7
我忘了提及,FoxPro DBF包含数据,并通过JDBC驱动程序连接到 iReport 。
子报表只有一个字段,其中包含以下表达式:
($F{commissionInvoiceNetValue} != null && $F{commissionCreditNoteNetValue} != null)
? ($F{commissionInvoiceNetValue} - $F{commissionCreditNoteNetValue})
: ($F{commissionInvoiceNetValue} != null) ? $F{commissionInvoiceNetValue}
: ($F{commissionCreditNoteNetValue} != null) ? $F{commissionCreditNoteNetValue}
: ""
我该如何绕过它?
答案 0 :(得分:1)
SELECT
( SELECT IFNULL (SUM (commissionInvoice.netto ), 0) AS commissionInvoiceNetValue
FROM tckopf AS commissionInvoice
WHERE commissionInvoice.referenzid = 1
AND commissionInvoice.btyp = 5 )
-
( SELECT IFNULL (SUM (commissionCreditNote.netto), 0) AS commissionCreditNoteNetValue
FROM tckopf AS commissionCreditNote
WHERE commissionCreditNote.referenzid = 1
AND commissionCreditNote.btyp = 6 )
AS commissionResult
和以下表达式的字段:
$F{commissionResult}
现在我得到了理想的结果。
答案 1 :(得分:0)
我很瘦你可以通过外连接解决这个问题:
select ifnull(sum (cDoc.netto), 0) as cCNValue, CInvNoteVal.Val
from tckopf as cDoc
FULL OUTER JOIN
(select ifnull (sum (cDoc.netto ), 0) AS Val, referenzid
from tckopf as cDoc
where cDoc.referenzid = $P{document_id} and cDoc.btyp = 7) as CInvNoteVal
ON CInvNoteVal.referenzid = cDoc.referenzid
where cDoc.referenzid = $P{document_id} and cDoc.btyp = 8