【问题标题】:Charting the data from database and merging row with the same value绘制数据库中的数据并合并具有相同值的行
【发布时间】:2020-04-03 03:05:45
【问题描述】:

我想创建一个图表来读取我的数据库中的类别列。我有重复的类别,因为它是通用术语,我注意到了这一点。

我有很多“短”切片:

我不知道如何合并具有相同名称的类别并添加其值..

这是我的代码

MySqlCommand cmd = new MySqlCommand("Select * From sketchit.inventory;", dc.con);
MySqlDataReader myreader;
try {
    dc.con.Open();
    myreader = cmd.ExecuteReader();
    while (myreader.Read()) {

        this.chart1.Series["Report 1"].Points.AddXY(myreader.GetString("Category"), myreader.GetInt32("Stocks"));
        chart1.ChartAreas["ChartArea1"].AxisX.Interval = 1;

    }
}
catch(Exception ex) {
    MessageBox.Show(ex.Message);
}
dc.con.Close();

【问题讨论】:

    标签: c# mysql sql winforms charts


    【解决方案1】:

    使用聚合。

    SELECT category,
           sum(stocks) stocks
           FROM sketchit.inventory
           GROUP BY category;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-05-21
      • 1970-01-01
      • 1970-01-01
      • 2021-03-06
      • 1970-01-01
      • 2017-05-18
      • 1970-01-01
      相关资源
      最近更新 更多