This is related to Winforms/C#/ MYSQL. I have the following table:
Net Amount / DATE
50 /2013-3-15
40/ 2013-11-10
30 / 2013-3-25
The program lets the user picks the month he wants to see data from and ideally the output should be a graph ( which i know how to do) to demonstrate the total net amount vs month. The output should be something like the following:
Net Amount / Month
80/March
40/November
Someone suggested I try this :
var selectdataforGraph = "SELECT SUM(AMOUNT_NET) AS Amount_Net, MONTH(date_Check) as Month FROM testingproject.incomeinformation WHERE";
var monthList = string.Join(",", selectedMonth);
selectdataforGraph += " YEAR(date_check) = " + selected_year;
selectdataforGraph += " AND MONTH(date_check) in (" + monthList + ")";
but when I run the query in the database
SELECT SUM(Amount_Net) AS Amount_Net, Month(date_check) AS Selected_Month FROM testingproject.incomeinformation WHERE YEAR(date_check) AND MONTH(date_check) in (1,11);
The result is the total Amount_Net Sum for both months something like this:
Amount_Net/Selected_Month
120/11
I did try to make another table with the Net Amount already calculated in per month but since i need to select multiple months in some cases, the column where it has the month is a varchar the month in part of the query above doesn't work. I could also just redesign the new table with the date column but i feel like I'm so close with the first response. I also know i should use parameters to avoid sql injections but this is more for quick demonstration of the problem.