Re: MySQL query for average records per day

From: Date: Thu, 16 Sep 2004 20:24:22 +0000
Subject: Re: MySQL query for average records per day
References: 1 2 3 4  Groups: php.general 
Request: Send a blank email to php-general+get-196910@lists.php.net to get a copy of this message
John Holmes wrote:
From: "Greg Donald" <destiney@gmail.com>
You can't get the average and a count in the same query
Sure you can. mysql> select count(number), avg(number) from numbers;
Depends how you interpret his request, I guess. I took it as a request for the count of records per day and then the average of those counts. So, if you had D1 D1 D1 D1 D2 D2 D3 The count would be D1 - 4 D2 - 2 D3 - 1 and the average would be (4+2+1)/3 = 2.333. Can you get that in one query? depends what the OP was after, though... ---John Holmes...
Jay Blanchard's worked perfectly: "SELECT (COUNT(date1)/COUNT(DISTINCT(date1))) AS average FROM $table_name where date1 != '$today'"; I was looking for the average amount of records (submissions) per day. Thanks. Jeff

« previous php.general (#196910) next »