Hi,
I have a MySQL DB and I am trying to set up a report page. To do so I need to be able to add the data in 6 or 7 fields into a single field for use in a summary report.

How can I do that? SUM() seems to consider only one field at a time.

For example, if I had a zoo database with the following fields:

Date| Lions| Tigers| Bears
1/1 | 2 | 3 | 2
1/2 | 1 | 0 | 2
1/3 | 0 | 2 | 3

I would want to generate a report that would tell me the date and the total number of animals added to the zoo for that date. 1/1 = 7; 1/2 = 3; 1/3 = 5

Any ideas? All help greatly appreciated!!

- Roland

I discovered the answer, at least one way to achieve my goal.

In the SELECT statement i found that you can add fields together in the following fashion:

SELECT *, (lions + tigers + bears) AS total FROM... etc...

The virtual field "total" will give me the results of my desired calculation.

I hope this helps someone else! If there is a better way for me to do this I am open to new ideas!

Thanks.

- Roland

Hi,
I have a MySQL DB and I am trying to set up a report page. To do so I need to be able to add the data in 6 or 7 fields into a single field for use in a summary report.

How can I do that? SUM() seems to consider only one field at a time.

For example, if I had a zoo database with the following fields:

Date| Lions| Tigers| Bears
1/1 | 2 | 3 | 2
1/2 | 1 | 0 | 2
1/3 | 0 | 2 | 3

I would want to generate a report that would tell me the date and the total number of animals added to the zoo for that date. 1/1 = 7; 1/2 = 3; 1/3 = 5

Any ideas? All help greatly appreciated!!

- Roland

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.