SELECT quantity,duration_minutes,
duration_seconds,
quantity /
SUM(duration_minutes + duration_seconds) as total
From process_data
GROUP BY quantity,duration_minutes,
duration_seconds
The output comes back as 1.6, how do i just round to two using the math round function?
Thanks in advance.
11-05-2012, 02:02 PM
NogDog
PHP Code:
echo round($value);
...should be sufficient
11-05-2012, 02:37 PM
Supplement
Thanks NogDog,
That worked well, although it's outputting to the nearest decimal but i need it to output to the nearest whole number. I created a new variable $total...
Here's what i got:
PHP Code:
<?php
$total = sql::query("SELECT
quantity,duration_minutes,
duration_seconds,
quantity /
SUM(duration_minutes + duration_seconds) as total
From process_data
GROUP BY quantity,duration_minutes,
duration_seconds")
?>
<?php echo ROUND($total); ?>
total is 1.688
I would like the result to be "2"
but rather it's giving me "17"
More help would be greatly appreciated.
11-05-2012, 02:50 PM
Supplement
I thought the syntax was something like:
ROUND ('$total',00.00) right after the SELECT?
11-05-2012, 03:04 PM
NogDog
Well, $total is probably a resource ID at that point, not the value of that column in the result record. You probably need to use the applicable "fetch" method for whichever database extension you're using. If you want the SQL to round it for you, the specifics may depend on which flavor of DBMS you are using -- with MySQL it should be something like:
Code:
ROUND(SUM(duration_minutes + duration_seconds)) as total
11-05-2012, 03:53 PM
Supplement
I'm stuck.
11-05-2012, 04:06 PM
Supplement
you're right.
when i:
<?php echo print($total_duration);?>
it returned Resource id #211
=/
<?php
$total_duration = sql::query("SELECT
quantity,duration_minutes,
duration_seconds,
quantity /
SUM(duration_minutes + duration_seconds) as total_duration
From process_data
GROUP BY quantity,duration_minutes,
duration_seconds");