Jump to content

Totaling a column outside SQL statement (repost)


TecTao

Recommended Posts

I'm familiar with the sum (pay_amount) as total

 

in the Sql statement.  but since I am joining about 4 tables and the 'pay_amount' is not in the first table, I was hoping there was a command that could total the numbers in the column rather then write a sql statement.

 

the column $pay_amount is monthly amounts for a program.  My select statement for a particular member produces a table of with each program and amount the member has signed up for.

 

I need to get the sum of the $pay_amount column.  I'm looking for a function that will sum that column and not do it through the sql statement.

 

Thanks,

m

Link to comment
Share on other sites

your post is difficult to follow, if I read it right a foreach loop would work

 

$count = 0;

foreach ($result as $row) {

   $count = $count + $row['pay_amount'];

}

 

good chance that's not what your looking for, might want to rethink the question, you'd be surprised how many times you come up with your own answer by thinking through the question,

 

couldn't count the number of posts I've written only to come up with the answer to my own question half way through

Link to comment
Share on other sites

Yes your write, it was a little confusing.

 

I'm not looking for a total row count.  I'm looking for a total of the variables without having to write the sum() as totals into the sql query since it is a join statement joining about 4 tables.

 

for example the query statement returns 4 rows with the numbers 5,5,10,5 in the "pay_amount" column.

 

Is there a function to total the variables so that the amount is obviously 25.  I was thinking that maybe there was a function like the formatting function.  Something outside of the sql statement.

 

Thanks again

m

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.