datadriven — 2013-02-23T22:06:18-05:00 — #1
This is for a single column, and I don't want to group - so not using AVG
Want to just average all the numerical values in a column, into a single result.
What is this missing?
$result = "SELECT amounts FROM inventory
(SUM( inventory.amounts ) / ( COUNT( mysql_num_rows($result))";
Aside from this, what would be needed to get a median value? Divide mysql_num_rows by 1/2 ?
r937 — 2013-02-24T03:45:30-05:00 — #2
SELECT SUM(amounts) / COUNT(*)
datadriven — 2013-02-24T13:55:38-05:00 — #3
You probably already know it but for others here. Below gives
Resource id #5
...Without the fetch.
$result = "SELECT SUM(amounts) / COUNT(*) FROM inventory";
$paid = mysql_query($result);
$row = mysql_fetch_array($paid);
$test = $row; <font color='#0000ff'>// needed for echo
r937 — 2013-02-24T14:04:15-05:00 — #4
you asked a database question, i gave you a database answer
if that doesn't work in your php code, then you need to ask a php question in that form
meanwhile, try assigning a column alias and referencing that (not sure how, because i don't do php)
SELECT AVG(amounts) [B]AS my_average[/B]