Re: Feeling a bit brain dead, please help in maths: averages
| From: | Curt Zirzow | Date: | Wed, 17 Sep 2003 21:34:34 +0000 |
| Subject: | Re: Feeling a bit brain dead, please help in maths: averages | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-162933@lists.php.net to get a copy of this message | ||
* Thus wrote Craig Lonsbury (craig@topdraw.com):
> off the top of my head:
>
> SELECT AVG(age), SUM(salTotal)
> FROM blah
> WHERE section = 3
>
> i'm not sure if you can use the 2 functions in the same query,
> you might have to break it into 2 queries.
Yes you can. And if you have other fields in the select you add a
group by to the sql statement
SELECT AVG(age), SUM(salTotal), otherfield
FROM blah
WHERE section = 3
group by otherfield
Assuming this is mysql:
http://www.mysql.com/doc/en/GROUP-BY-Functions.html
Curt
--
"I used to think I was indecisive, but now I'm not so sure."