获取所有当前月份和年份的交易,并避免显示上一年的交易

时间:2020-07-01 05:32:08

标签: c# mysql

我有一个带有图表的C#应用​​程序,该图表显示了每月的交易量。但我想显示当前年份的月份,而不显示过去一年的交易。

这是我要实现的方案,我想在图表中显示2020年7月1日的值,而不显示2019年7月7日或去年的所有交易。

我附上了电费单作为参考

public void LoadChart1()
    {
        con.conDB.Open();
        sda = new MySqlDataAdapter("SELECT Monthname(sdate) as month, IFNULL(sum(total),0.0) as total from tblcart where status like 'Sold' GROUP BY Month(sdate)", con.conDB);
        ds = new DataSet();

        sda.Fill(ds, "Sales");
        chart2.DataSource = ds.Tables["Sales"];
        Series series1 = chart2.Series["Series1"];
        series1.ChartType = SeriesChartType.Bar;
        series1.Name = "SALES";
        var chart = chart2;
        chart.Series[series1.Name].XValueMember = "month";
        chart.Series[series1.Name].YValueMembers = "total";
        chart.Series[0].IsValueShownAsLabel = true;
        //chart.Series[0].LegendText = "#";

        con.conDB.Close();
    }

mysql Chart Picture for reference

1 个答案:

答案 0 :(得分:0)

我不确定您到底想要什么。但是,如果您只想要过去一年中的值,则将其添加到您的SQL语句where子句中:

and sdate >= DATE_SUB(NOW(), INTERVAL 1 YEAR)

如果您只想要同一日历年(例如2020年)内的值,则添加以下内容:

and YEAR(sdate) = YEAR(NOW())