我想创建RDLC折线图报告进行比较 - 3个不同时期的许多部门的1个项目。
我应该从数据库中检索哪些数据字段?我使用下面的查询,但这对图表来说还不够。
SELECT d.DepartmentName,
SUM(CASE WHEN r.Date BETWEEN '2016-10-01' AND '2016-10-31' THEN ri.RequiredQty ELSE 0 END) FirstMonth,
SUM(CASE WHEN r.Date BETWEEN '2016-11-01' AND '2016-11-30' THEN ri.RequiredQty ELSE 0 END) SecondMonth,
SUM(CASE WHEN r.Date BETWEEN '2016-12-01' AND '2016-12-31' THEN ri.RequiredQty ELSE 0 END) ThirdMonth
FROM RequisitionItem ri, Requisition r, [User] u, Department d
WHERE ri.RequisitionID = r.RequisitionID
AND r.UserID = u.UserID
AND u.DepartmentID = d.DepartmentID
AND ri.ItemID = 'C001'
AND d.DepartmentID IN ( 'BIOL' , 'COMM', 'BIZL', 'CPSC')
GROUP BY d.DepartmentName
答案 0 :(得分:0)
这不是获取数据以生成图表的正确方法。 您的选择的每一行应包含3个信息
所以你的查询应该像这样的东西
SELECT d.DepartmentName, --series field
LEFT(CONVERT(varchar, r.Date,112),6) Period, --X Axis Values
SUM(ri.RequiredQty) Quantity, --Y axis values
FROM RequisitionItem ri, Requisition r, [User] u, Department d
WHERE ri.RequisitionID = r.RequisitionID
AND r.UserID = u.UserID
AND u.DepartmentID = d.DepartmentID
AND ri.ItemID = 'C001'
AND d.DepartmentID IN ( 'BIOL' , 'COMM', 'BIZL', 'CPSC')
GROUP BY d.DepartmentName, LEFT(CONVERT(varchar, r.Date,112),6)
信息:此指令LEFT(CONVERT(varchar, r.Date,112),6)
用于转换YYYYMM字段中的日期字段,以便按组部门和月份一起分组。