我们在数据库表中有一个日期列。我们需要检查日期是否多次出现并添加另一列的总和,称为“hours_remaining”。
例如,在2017年11月30日,我们在'hours_remaining'列中有两个任务,分别为3和4。我们需要将这些值相加并绘制到Visual Studio图表中。
con.Open();
SqlCommand cmd = new SqlCommand("SELECT * FROM SprintTask INNER JOIN Sprint ON SprintTask.sprint_id = Sprint.Id WHERE Sprint.Id = @sid", con);
cmd.Parameters.AddWithValue("@sid", Request.QueryString["sid"]);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataSet st = new DataSet();
sda.Fill(st, "task_start_date");
Chart1.DataSource = st.Tables["task_start_date"];
Chart1.Series["Series1"].XValueMember = "task_start_date";
Chart1.Series["Series1"].YValueMembers = "hours_remaining";
this.Chart1.Titles.Add("This is a test chart ");
Chart1.Series["Series1"].ChartType = SeriesChartType.Line;
Chart1.Series["Series1"].IsValueShownAsLabel = true;
答案 0 :(得分:0)
正如@mjwills在评论中写道,你需要使用group by和sum:
SELECT task_start_date, SUM(hours_remaining) As hours_remaining
FROM SprintTask
INNER JOIN Sprint ON SprintTask.sprint_id = Sprint.Id
GROUP BY task_start_date
WHERE Sprint.Id = @sid