1

几天前我问了一个类似的问题,但提出一个更具挑战性的问题并没有什么坏处。长话短说,我从 SQL Server 取回一个数据集,但我不知道如何在报告中正确分组。

以下是一些示例数据:

SELECT companyID = 106, userID = 71152, productID = 11,taxID = 216, quantity = 78, total = 71325 UNION ALL
SELECT companyID = 106, userID = 71152, productID = 11,taxID = 245, quantity = 41, total = 40297 UNION ALL
SELECT companyID = 106, userID = 71152, productID = 12,taxID = 246, quantity = 12, total = 7685 UNION ALL
SELECT companyID = 106, userID = 51154, productID = 11,taxID = 216, quantity = 92, total = 84311 UNION ALL
SELECT companyID = 106, userID = 51154, productID = 11,taxID = 245, quantity = 145, total = 139329 UNION ALL
SELECT companyID = 106, userID = 51154, productID = 11,taxID = 275, quantity = 80, total = 87513 UNION ALL
SELECT companyID = 106, userID = 51154, productID = 12,taxID = 246, quantity = 23, total = 15800 UNION ALL
SELECT companyID = 106, userID = 51154, productID = 12,taxID = 277, quantity = 12, total = 8060 UNION ALL
SELECT companyID = 106, userID = 51221, productID = 11,taxID = 216, quantity = 4, total = 3655 UNION ALL
SELECT companyID = 106, userID = 51221, productID = 11,taxID = 245, quantity = 29, total = 29692 UNION ALL
SELECT companyID = 106, userID = 51221, productID = 11,taxID = 275, quantity = 55, total = 63679 UNION ALL
SELECT companyID = 106, userID = 51221, productID = 12,taxID = 246, quantity = 3, total = 2390 UNION ALL
SELECT companyID = 106, userID = 61221, productID = 11,taxID = 216, quantity = 162, total = 138403 UNION ALL
SELECT companyID = 106, userID = 61221, productID = 11,taxID = 245, quantity = 130, total = 123760 UNION ALL
SELECT companyID = 106, userID = 61221, productID = 11,taxID = 275, quantity = 19, total = 22073 UNION ALL
SELECT companyID = 106, userID = 61221, productID = 12,taxID = 246, quantity = 1, total = 415 UNION ALL
SELECT companyID = 114, userID = 71198, productID = 11,taxID = 245, quantity = 131, total = 134039 UNION ALL
SELECT companyID = 114, userID = 71198, productID = 11,taxID = 275, quantity = 120, total = 141423 UNION ALL
SELECT companyID = 114, userID = 71198, productID = 12,taxID = 246, quantity = 70, total = 36590 UNION ALL
SELECT companyID = 114, userID = 71198, productID = 12,taxID = 249, quantity = 1, total = 980 UNION ALL
SELECT companyID = 114, userID = 71198, productID = 12,taxID = 276, quantity = 1, total = 790 UNION ALL
SELECT companyID = 114, userID = 71198, productID = 12,taxID = 277, quantity = 64, total = 41380 UNION ALL
SELECT companyID = 114, userID = 71198, productID = 12,taxID = 279, quantity = 1, total = 690 UNION ALL
SELECT companyID = 114, userID = 71198, productID = 12,taxID = 293, quantity = 1, total = 760 UNION ALL
SELECT companyID = 114, userID = 71204, productID = 11,taxID = 245, quantity = 48, total = 48049 UNION ALL
SELECT companyID = 114, userID = 71204, productID = 11,taxID = 275, quantity = 41, total = 43729 UNION ALL
SELECT companyID = 114, userID = 71204, productID = 12,taxID = 246, quantity = 1, total = 450 UNION ALL
SELECT companyID = 114, userID = 71204, productID = 12,taxID = 249, quantity = 7, total = 5895 UNION ALL
SELECT companyID = 114, userID = 71204, productID = 12,taxID = 277, quantity = 2, total = 1300 UNION ALL
SELECT companyID = 114, userID = 71204, productID = 12,taxID = 279, quantity = 2, total = 2230 UNION ALL
SELECT companyID = 614, userID = 71198, productID = 11,taxID = 216, quantity = 54, total = 48748 UNION ALL
SELECT companyID = 614, userID = 71198, productID = 11,taxID = 245, quantity = 121, total = 113030 UNION ALL
SELECT companyID = 614, userID = 71198, productID = 12,taxID = 246, quantity = 11, total = 6080 UNION ALL
SELECT companyID = 614, userID = 71204, productID = 11,taxID = 216, quantity = 14, total = 11519 UNION ALL
SELECT companyID = 614, userID = 71204, productID = 11,taxID = 245, quantity = 32, total = 29103 UNION ALL
SELECT companyID = 614, userID = 71204, productID = 12,taxID = 249, quantity = 3, total = 3535

基本上,我们以不同的税率销售特定产品。我想显示按 companyID、userID、productID 分组数据的数据,并显示数量和总计字段的总和,类似于:

companyID   userID      productID   sumQuantity sumTotal
----------- ----------- ----------- ----------- -----------
106         51154       11          317         311153
106         51154       12          35          23860
106         51221       11          88          97026
106         51221       12          3           2390
106         61221       11          311         284236
106         61221       12          1           415
106         71152       11          119         111622
106         71152       12          12          7685
114         71198       11          251         275462
114         71198       12          138         81190
114         71204       11          89          91778
114         71204       12          12          9875
614         71198       11          175         161778
614         71198       12          11          6080
614         71204       11          46          40622
614         71204       12          3           3535

SSRS 无法以这种方式对行进行分组,因为 taxID 是唯一的。结果可以在这些屏幕截图中看到。

如何强制 SSRS 将多条记录合并到一行中?

4

3 回答 3

3

为什么不直接从 SQL 查询的 select 和 grouping 子句中删除 Taxid 呢?这会让你得到你想要的。

于 2009-06-10T14:55:21.637 回答
0

听起来您可能想考虑创建自己的包含汇总总数的计算字段。

编辑:就像我对另一个答案的评论一样:创建一个不同的数据集,它将以您想要的方式聚合数据。除非您正在处理返回的巨大行,否则这不应该是一个性能问题,从长远来看,它可能比尝试从可能不合适的数据集中破解一个解决方案要好得多。

于 2009-06-10T14:52:21.597 回答
0

看起来您将标题放在分组行中,将数据放在详细信息中。将表头放在表头行,数据放在分组行,删除或隐藏明细。

于 2009-06-10T15:15:35.167 回答