我需要用数据填充条形图。我已经准备好了一切。我有用于收集数据的 sql 查询。
我正在寻找的是提供当月和过去 11 个月(总共 12 个月)数据的最佳方式。
这段代码将为我提供当月到今天的信息。我该如何修改它,这样它也会给我前 11 个月的信息?
是否会对查询进行此修改,或者我们是否会循环查询 12 次?
protected void FillChart ()
{
DateTime now = DateTime.Now;
DateTime startDate = now.AddDays( 1 - now.Day );
DateTime endDate = now;
string query;
query = "SELECT SUM(case when r.Type in ('Programming-Billable', 'Consulting-Billable') then r.Minutes_Spent";
query += " end) AS 'Custom Programming and Consulting',";
query += " SUM(case when r.Type in ('Data Maintenance', 'Tech Support-Billable', 'Training') then r.Minutes_Spent";
query += " end) AS 'Tech. Support / Data Maint. / Training'";
query += " FROM TK_Project p ";
query += " INNER JOIN TK_Task t";
query += " ON p.Project_ID = t.Project_ID ";
query += " JOIN TK_Time_Record r";
query += " ON t.ID = r.Task_ID";
query += " WHERE p.Company = " + Session[ "Distid" ];
query += " AND p.Name ='Technical Support' ";
query += " AND r.Work_Date BETWEEN '" + startDate + "' AND '" + endDate + "' ";
query += " AND r.Type NOT LIKE '%non%'";
DataTable data = GeneralFunctions.GetData( query );
}
该查询当前返回以下结果:
Custom Programming and Consulting Tech. Support / Data Maint. / Training
90 105
编辑:
SELECT SUM(case when r.Type in ('Programming-Billable', 'Consulting-Billable') then r.Minutes_Spent
end) AS 'Custom Programming and Consulting',
SUM(case when r.Type in ('Data Maintenance', 'Tech Support-Billable', 'Training') then r.Minutes_Spent
end) AS 'Tech. Support / Data Maint. / Training'
FROM TK_Project p
INNER JOIN TK_Task t
ON p.Project_ID = t.Project_ID
JOIN TK_Time_Record r
ON t.ID = r.Task_ID
WHERE p.Company = 162 AND p.Name ='Technical Support'
AND r.Work_Date BETWEEN '04/01/2001' AND '04/30/2012'
AND r.Type NOT LIKE '%non%'