Я задал похожий вопрос несколько дней назад, но нет ничего плохого в том, чтобы поставить более сложный вопрос. Короче говоря, я возвращаю набор данных из 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 объединить несколько записей в одну строку?