CodeCharge Studio
search Register Login  

Visual Web Reporting

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> PHP

 Help with MySQL SUM( ) statement

Print topic Send  topic

Author Message
johnhendy
Posted: 12/12/2004, 12:19 PM

Hi, :-)
I wonder if any one can help? I am quite new to mysql and php and have managed to get

along. I have come up against a rather strange occurrence produced by mysql. I have 2

tables, one called coursecard and the other called courseback. The fields within the

tables are identical. The Coursecard table contains details of the first nine holes of a

golf course and the courseback table contains details of the last nine holes. I didn't set

the tables up and I cant change them because they are used else where on a website.

So what I managed to do, was sum the first nine holes and arrive at a total, thenthe same

to the last nine. All Ok at this point. Now I need to sum the total of the first nine and

the last nine and provide a total for all 18 holes.

This is how I got totals from the coursecard

SELECT (SUM(blueyards)) as TOTAL1, (SUM(whiteyards)) as TOTAL2,
(SUM(yellowyards)) as TOTAL3, (SUM(menspar)) as TOTAL4,
(SUM(redyards)) as TOTAL5,
(SUM(ladiespar)) as TOTAL6
FROM coursecard

And this is the results for The coursecard blueyards = 3062

This is how I got totals from the courseback

SELECT (SUM(blueyards)) as TOTAL7, (SUM(whiteyards)) as TOTAL8,
(SUM(yellowyards)) as TOTAL9, (SUM(menspar)) as TOTAL10,
(SUM(redyards)) as TOTAL11,
(SUM(ladiespar)) as TOTAL12
FROM courseback

And this is the results for The courseback blueyards = 3048


Now I need to aquire the total of the two blueyards as well as the rest of the fields, but

this is where I have had some strange values appear, which obviously tells me I am doing

something wrong. Can anyone help, it should be simple, but I am stuck.

I used the following statement to aquire both totals again but this time add them

together.

SELECT (SUM(coursecard.blueyards) + (SUM(courseback.blueyards))) as TOTAL1
FROM courseback,coursecard

And this is the results for The above statement blueyards Total = 27558 :-/

looking forward to you assistance.
klwillis


Posts: 428
Posted: 12/13/2004, 10:54 AM

What is the 'where clause' you are using for the combined
summation in the second select statement?

~~~
I used the following statement to aquire both totals again but this time add them

together.

SELECT (SUM(coursecard.blueyards) + (SUM(courseback.blueyards))) as TOTAL1
FROM courseback,coursecard

And this is the results for The above statement blueyards Total = 27558

looking forward to you assistance.
_________________
Kevin Willis, VP/CIO
HealthCare Information Technology Specialist
http://www.nexushealthcare.com
"Fast - Convenient - Quality-Care"

Medical Software Consulting Services
Email : klwillis@nexushealthcare.com
Skype : klwillis2006
View profile  Send private message
johnhendy5

Posts: 12
Posted: 12/14/2004, 4:54 AM

:-)

Hi, Just to let you know there is no where clause in the statement. This is because I am not sure what it should be. Stupid I know.
_________________
Thanks
View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

MS Access to Web

Convert MS Access to Web.
Join thousands of Web developers who build Web applications with minimal coding.

CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.