Jump to content

eady mysql query question


Guest bennyuk

Recommended Posts

Guest bennyuk

Hi

If I have a table (tableA) with a rows with 2 decimal fields (field1 & field2), and I want to find the total value of field1 * field2 for each row and add them all together, is there 1 line in mysql that would do it.

All I can think of at the moment is a WHILE loop with a running total, but I'm sure there mist be one nice mysql statement tha tcan return the result?:-

$sql_select = mysql_query("SELECT * FROM tableA");

$count1 = 0;

while ($row = mysql_fetch_array($sql_select))

{

$fieldA = $row["fieldA"];

$fieldB= $row["fieldB"];

$count1 = $count1 + ($fieldA * $fieldB);

}

echo "result = $count1";

PS I'm stuck on old MySQL Version 3.23.54

Any ideas?

PS excuse my typos in the title ( :D )

Edited by bennyuk
Link to comment
Share on other sites

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.   Paste as plain text instead

  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...