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?
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
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"
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
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
quantity,duration_minutes,
duration_seconds,
quantity /
SUM(duration_minutes + duration_seconds) as total_duration
From process_data
GROUP BY quantity,duration_minutes,
duration_seconds");
Bookmarks