Re: MySQL query for average records per day
| From: | Greg Donald | Date: | Thu, 16 Sep 2004 19:46:59 +0000 |
| Subject: | Re: MySQL query for average records per day | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-196901@lists.php.net to get a copy of this message | ||
On Thu, 16 Sep 2004 15:15:01 -0400, John Holmes
<holmes072000@charter.net> wrote:
> You can't get the average and a count in the same query
Sure you can.
> desc numbers;
+--------+---------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------+---------+------+-----+---------+-------+
| number | int(11) | | | 0 | |
+--------+---------+------+-----+---------+-------+
1 row in set (0.00 sec)
mysql> select * from numbers;
+--------+
| number |
+--------+
| 1 |
| 2 |
| 1 |
| 2 |
| 1 |
| 2 |
| 1 |
| 2 |
| 1 |
| 2 |
| 3 |
| 4 |
| 3 |
| 4 |
| 3 |
| 4 |
| 3 |
| 4 |
+--------+
18 rows in set (0.00 sec)
mysql> select count(number), avg(number) from numbers;
+---------------+-------------+
| count(number) | avg(number) |
+---------------+-------------+
| 18 | 2.3889 |
+---------------+-------------+
1 row in set (0.00 sec)
--
Greg Donald
http://gdconsultants.com/
http://destiney.com/