this related winforms/c#/ mysql. have following table:
net amount / date
50 /2013-3-15
40/ 2013-11-10
30 / 2013-3-25
program lets user picks month wants see data , ideally output should graph ( know how do) demonstrate total net amount vs month. output should following:
net amount / month
80/march
40/november
suggested try :
var selectdataforgraph = "select sum(amount_net) amount_net, month(date_check) month testingproject.incomeinformation where"; var monthlist = string.join(",", selectedmonth); selectdataforgraph += " year(date_check) = " + selected_year; selectdataforgraph += " , month(date_check) in (" + monthlist + ")"; but when run query in database
select sum(amount_net) amount_net, month(date_check) selected_month testingproject.incomeinformation year(date_check) , month(date_check) in (1,11); the result total amount_net sum both months this:
amount_net/selected_month
120/11
did try make table net amount calculated in per month since need select multiple months in cases, column has month varchar month in part of query above doesn't work. redesign new table date column feel i'm close first response. know should use parameters avoid sql injections more quick demonstration of problem.
you need add group by sql statement after where clause. otherwise, mysql aggregates single row, choosing arbitrary month:
the syntax line is:
group month(date_check), year(date_check) i suggest include year in select.
your statement be:
var selectdataforgraph = "select sum(amount_net) amount_net, month(date_check) month, year(date_check) year testingproject.incomeinformation where"; var monthlist = string.join(",", selectedmonth); selectdataforgraph += " year(date_check) = " + selected_year; selectdataforgraph += " , month(date_check) in (" + monthlist + ")"; selectdataforgraph += " group month(date_check), year(date_check)";
Comments
Post a Comment