我正在撰写报告,我正在显示所有项目的total cost
,具体取决于所选的date range
。
目前这些项目都显示完全正常,但如果您发现某些项目多次显示(默认情况下很好)。
我希望每个项目总计一次,并且每次只显示一次。
示例:
在我的照片中,您可以看到部件SOFTT-W
显示5次。我想让它只出现一次,但是Cost
这些都被总计和显示。此外,我希望所有项目都能发生同样的事情。
我有办法做到这一点吗?
我将发布我的SQL代码并附上截图。
SELECT
COMPANY."NAME" AS COMPANY_NAME,
CUSTOMER."NAME" AS CUSTOMER_NAME,
SO."NUM" AS SO_NUM,
SOITEM."STATUSID" AS SOITEM_STATUSID,
PRODUCT."ID" AS PRODUCT_ID,
PART."NUM" AS PART_NUM,
SOITEM."QTYFULFILLED" AS SOITEM_QTYFULFILLED,
SO."COST" AS SO_COST,
PART."ID" AS PART_ID,
SO."DATECOMPLETED" AS SO_DATECOMPLETED,
CUSTOMER."ID" AS CUSTOMER_ID,
SOSTATUS."ID" AS SOSTATUS_ID,
PARTCOST."TOTALCOST" AS PARTCOST_TOTALCOST,
SOITEM."TOTALCOST" AS SOITEM_TOTALCOST,
SO."CUSTOMERID" AS SO_CUSTOMERID
FROM
"CUSTOMER" CUSTOMER INNER JOIN "SO" SO ON CUSTOMER."ID" = SO."CUSTOMERID"
INNER JOIN "SOITEM" SOITEM ON SO."ID" = SOITEM."SOID"
INNER JOIN "SOSTATUS" SOSTATUS ON SO."STATUSID" = SOSTATUS."ID"
INNER JOIN "PRODUCT" PRODUCT ON SOITEM."PRODUCTID" = PRODUCT."ID"
INNER JOIN "PART" PART ON PRODUCT."ID" = PART."DEFAULTPRODUCTID"
AND PART."ID" = PRODUCT."PARTID"
INNER JOIN "PARTCOST" PARTCOST ON PART."ID" = PARTCOST."PARTID",
"COMPANY" COMPANY
WHERE
SO."STATUSID" = 60
AND (PART."ID" != 947)
AND CUSTOMER."ID" = $P{customerID}
AND SO."DATECOMPLETED" BETWEEN $P{From} AND $P{To}
答案 0 :(得分:1)
最简单的解决方案是在声明结尾处使用订单。然后,您可以根据partnum在iReport中使用组,并总计总成本。
SELECT
COMPANY.NAME AS COMPANY_NAME,
CUSTOMER.NAME AS CUSTOMER_NAME,
SO.NUM AS SO_NUM,
SOITEM.STATUSID AS SOITEM_STATUSID,
PRODUCT.ID AS PRODUCT_ID,
PART.NUM AS PART_NUM,
SOITEM.QTYFULFILLED AS SOITEM_QTYFULFILLED,
SO.COST AS SO_COST,
PART.ID AS PART_ID,
SO.DATECOMPLETED AS SO_DATECOMPLETED,
CUSTOMER.ID AS CUSTOMER_ID,
SOSTATUS.ID AS SOSTATUS_ID,
PARTCOST.TOTALCOST AS PARTCOST_TOTALCOST,
SOITEM.TOTALCOST AS SOITEM_TOTALCOST,
SO.CUSTOMERID AS SO_CUSTOMERID
FROM
CUSTOMER CUSTOMER INNER JOIN SO SO ON CUSTOMER.ID = SO.CUSTOMERID
INNER JOIN SOITEM SOITEM ON SO.ID = SOITEM.SOID
INNER JOIN SOSTATUS SOSTATUS ON SO.STATUSID = SOSTATUS.ID
INNER JOIN PRODUCT PRODUCT ON SOITEM.PRODUCTID = PRODUCT.ID
INNER JOIN PART PART ON PRODUCT.ID = PART.DEFAULTPRODUCTID
AND PART.ID = PRODUCT.PARTID
INNER JOIN PARTCOST PARTCOST ON PART.ID = PARTCOST.PARTID,
COMPANY COMPANY
WHERE
SO.STATUSID = 60
AND (PART.ID != 947)
AND CUSTOMER.ID = $P{customerID}
AND SO.DATECOMPLETED BETWEEN $P{From} AND $P{To}
ORDER BY customer.name, part.num
变量设置: