我有这张桌子
SELECT ProductName, Grade, COUNT(Grade) AS count
FROM Inspection
WHERE (Branch = @branchno) AND (Date BETWEEN @DateFrom AND DATEADD(day, 1, @DateTo))
AND (Grade <> '')
GROUP BY ProductName, Grade
ORDER BY ProductName
并且报告矩阵包含我希望除以等级
的小计 | =Fields!grade.Value |Total
========================= =========================== ======
=Fields!ProductName.Value|=Sum(Fields!count.Value) |
但我一直试图让字段计数值除以总值,但有麻烦 因为我需要表格看起来像这个
Grade 1 | Grade 2 | Grade 3 | bad
======|========|=========|=========|=======
orange| 17.65% | 11.76% | 58.82% | 11.76%
------ -------- --------- ---------|--------
banana| 13.33% | 13.33% | 53.33% | 20.00%
我们可以通过以下方式获得
Grade 1 | Grade 2 | Grade 3 | bad | Total
======|========|=========|=========|=======|======
orange| 3/17 | 2/17 | 10/17 | 2/17 | 17
------ -------- --------- --------- ------- ------
banana| 2/15 | 2/15 | 8/15 | 3/15 | 15
感谢您的帮助
答案 0 :(得分:0)
您可以对特定分组或数据区域中的数据求和。请参阅this example from MSDN,其中总和超过“订单”分组:
=Sum(Fields!LineTotal.Value, "Order")
您还需要防止被零除错误。
答案 1 :(得分:0)
感谢来自http://www.codeproject.com/的Maciej,我们得到了这个工作
SELECT ProductName, Grade, COUNT(Grade) AS CountOfGrades, (SELECT COUNT(Grade) FROM Inspection WHERE (Branch = @branchno) AND (Date BETWEEN @DateFrom AND DATEADD(day, 1, @DateTo))
AND (Grade<>'') AND (productname=i.productname) AS TotalOfGrades
FROM Inspection as i.inspection
WHERE (Branch = @branchno) AND (Date BETWEEN @DateFrom AND DATEADD(day, 1, @DateTo))
AND (Grade <>'')
GROUP BY ProductName, Grade
ORDER BY ProductName