2016-02-25 43 views
1

我有一份报告显示partquantity根据所选的location。它是Fishbowl中成本层估价的修改版本。无法过滤掉iReport中的重复值

我已经能够得到的位置过滤工作,但现在的价值被重复,我无法弄清楚为什么。

这些都是屏幕截图,用于显示未选中并选中“全部重复打印”复选框时打印出的报告。 Checked- With Repeating Unchecked- Without Repeating

这是我的SQL查询


SELECT 
costlayer.qty AS Qty, costlayer.orgqty, costlayer.orgtotalcost, 
costlayer.totalcost AS TotalCost, costlayer.datecreated AS DateCreated, 
part.num AS PartNumber, part.description as PartDescription, asaccount.name as "InventoryAccount", 
company.name AS company, currency.symbol 

FROM CostLayer 
LEFT JOIN Part ON part.id = costlayer.partid 
LEFT JOIN Tag ON part.id = tag.partId 
LEFT JOIN Location ON tag.locationId = location.id 
LEFT JOIN LocationGroup ON location.locationGroupId = locationGroup.id 
LEFT JOIN asaccount ON part.inventoryaccountid = asaccount.id 
JOIN company ON company.id = 1 
LEFT JOIN currency ON currency.homeCurrency = 1 

WHERE 
costlayer.datecreated BETWEEN $P{dateRange1} AND $P{dateRange2} 
AND costlayer.statusid IN ($P!{ckShowActiveCostingLayers},$P!{ckShowFulfilledCostingLayers},$P!{ckShowVoidedCostingLayers}) 
AND UPPER(part.num) LIKE UPPER($P{partNum}) 
AND (UPPER(COALESCE(asaccount.name,'')) LIKE UPPER('%' || $P{AssetAccount} || '%')) 
AND LocationGroup.id LIKE $P{locationGroupID} 

ORDER BY (CASE WHEN $P{AssetAccount} NOT LIKE CAST('%' AS varchar(256)) THEN asaccount.name ELSE part.num END), part.num ASC, costlayer.id, costlayer.datecreated 
+1

由于您在价格/总表上重复记录,所以您应该尝试对其进行分组(按组)。由于我不太了解你的数据,所以不能给你确切的查询。 –

+1

如果你想要一个精确的答案,你需要显示的数据结构...我们需要知道表 –

+0

@PetterFriberg之间的所有关系对不起,我会发布它的一切,但Mamof似乎与Fishbowl的家人,所以我知道他明白了表。感谢您一直愿意帮助! – Ashton

回答

1

在看你的截图看来它是基于在每个位置标签的数量复制。这将来自加入标签以便能够过滤位置。通过添加一个独特的查询,它会清除重复的数据库值。这样做后,您可能会想要重新显示重复的值,因为如果您为给定部分进行相同的购买数量和价值,它将不会显示。

SELECT DISTINCT costlayer.qty AS Qty, costlayer.orgqty, costlayer.orgtotalcost, 
costlayer.totalcost AS TotalCost, costlayer.datecreated AS DateCreated, 
part.num AS PartNumber, part.description as PartDescription, asaccount.name as "InventoryAccount", 
company.name AS company, currency.symbol 

FROM CostLayer 
LEFT JOIN Part ON part.id = costlayer.partid 
LEFT JOIN Tag ON part.id = tag.partId 
LEFT JOIN Location ON tag.locationId = location.id 
LEFT JOIN LocationGroup ON location.locationGroupId = locationGroup.id 
LEFT JOIN asaccount ON part.inventoryaccountid = asaccount.id 
JOIN company ON company.id = 1 
LEFT JOIN currency ON currency.homeCurrency = 1 

WHERE costlayer.datecreated BETWEEN $P{dateRange1} AND $P{dateRange2} 
AND costlayer.statusid IN ($P!{ckShowActiveCostingLayers},$P!{ckShowFulfilledCostingLayers},$P!{ckShowVoidedCostingLayers}) 
AND UPPER(part.num) LIKE UPPER($P{partNum}) 
AND (UPPER(COALESCE(asaccount.name,'')) LIKE UPPER('%' || $P{AssetAccount} || '%')) 
AND LocationGroup.id LIKE $P{locationGroupID} 

ORDER BY (CASE WHEN $P{AssetAccount} NOT LIKE CAST('%' AS varchar(256)) THEN asaccount.name ELSE part.num END), part.num ASC, costlayer.id, costlayer.datecreated 
+0

你发布的SQL与我的发布有什么不同吗? – Ashton

+1

对不起,我从SQL编辑器中复制的文件没有激活,我错过了select的独特之处。我已经更新了它。 – Mamof

+1

@PetterFriberg是正确的,你也可以使用GROUP BY。在这个查询中,您可能只需要将您在select语句中使用的字段作为字段按组复制。 – Mamof