I have a client that wants a year end report that shows the data in its respective month column like this:
Income Jan Feb Mar ..... Dec
Rent 10.00 10.00 10.00 10.00
Expenses
Landscape 5.00 3.00 2.00 5.00
Net Income 5.00 7.00 8.00 5.00
All the transaction data is stored in one table like this
Create Table transaction(
id int,
date DATE,
amount DECIMAL 10,2,
account_type INT)
I’m not quite sure how to begin this. I’m using iReport as the report designer and mysql as the database. Is there an efficient way using SQL to get something like this? Is it better for me to do something like this SELECT date FROM transaction WHERE date between 1-01-2012 and 12-31-2012 to give me the results, then use my iReport to somehow split out the data into columns like the client wants?
I’m wondering what the best approach is and how I could accomplish this.
Thanks for your help and ideas.
Smit and Sam, thanks for your replies, I ended up using portions of both of your SQL examples, however, I ended up taking those examples and ultimately outputting the report in iReport. I had to create a column for each month and then used month(date) to separate out each month due to the requirements. So when the report ran it put each transaction under the month column for which it belonged to.