Jump to content


Adding numbers from the same column

  • Please log in to reply
1 reply to this topic

#1 ibanez270dx

  • Members
  • PipPipPip
  • Advanced Member
  • 53 posts

Posted 27 July 2006 - 05:23 PM

I am having problems with a little section of my script (running on MySQL 4). Pretty much, I need to extract all everything in my table (no problem), but then I need to take all the numbers (from column "dwntime_hrs") in each row and add them together. How would I go about doing this?

My script looks like this thus far:

$sql = "SELECT *, SUM(dwntime_hrs) as total_downtime FROM $table_name WHERE aircraft_id = '$_POST[viewlog]' ORDER BY dwntime_date";
$result = @mysql_query($sql,$connection) or die(mysql_error());

while ($row = mysql_fetch_array($result))

$aircraft_id = stripslashes($row['aircraft_id']);
$aircraft_name = stripslashes($row['aircraft_name']);
$dwntime_type = stripslashes($row['dwntime_type']);
$dwntime_date = stripslashes($row['dwntime_date']);
$dwntime_hrs = stripslashes($row['dwntime_hrs']);
$dwntime_reason = stripslashes($row['dwntime_reason']);
$dwntime_log = stripslashes($row['dwntime_log']);
$dwntime_log_by = stripslashes($row['dwntime_log_by']);
$total_dwntime_hrs = $row['total_downtime'];

However, I get this error:

Mixing of GROUP columns (MIN(),MAX(),COUNT()...) with no GROUP columns is illegal if there is no GROUP BY clause

Any ideas?

- Jeff

#2 ryanlwh

  • Staff Alumni
  • Advanced Member
  • 511 posts

Posted 27 July 2006 - 05:47 PM

you can't use SUM together with other fields unless you specify the GROUP BY clause. if you're trying to get the total of all the records, you can use a different query to select it, or just add it up in php. if you want the total of a specific set of "groups" (like total for different dwntime_type's) then you should specify GROUP BY dwntime_type.

In your context, I guess you're trying to get the total of all dwntime_hrs?
Please use EDIT * 100...
Please use
or [php] * 1000...


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users