0

my table design is

date     income  expenses  

2011-08-5   1000    500
2011-09-6   7000    400
2011-10-7   2000    300

I have daily expenses and Income in the above table.I need to retrieve monthly(sum of daily) income and expenses for particular year.
How should i write query for that .
Pls help me
Thanks in advance

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by anand01
0

Hello,

This is quick and dirty since I don't know the real field names or table name but something like this should work:

select 
left(`date`,7) as 'Year-Month',
sum(income) as Monthly_Income,
sum(expenses) as Monthly Expenses
from 
mytable
group By 'Year-Month'

You should get a monthly total on each line.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.