List:General Discussion« Previous MessageNext Message »
From:Bill Adams Date:October 28 2005 5:49pm
Subject:'GROUP BY' behavior
View as plain text  
All, 

In the following query, some of the values are averaged over several
rows, but some are not:

SELECT hostname, volname, qtreename, round(avg(used/allocated*100),0), 
	round(avg(used)), allocated, available
	FROM quota_entries
	WHERE date_sub(now(), interval 1 day) < timestamp
	GROUP BY qtreename,hostname

My questions: 
From which of the several averaged rows do 'allocated' and 'available'
come in the results?
Can I control this?  I would like the row with maximum timestamp.

Thanks,
Bill

+-----------+------------------+------+-----+---------+----------------+
| Field     | Type             | Null | Key | Default | Extra          |
+-----------+------------------+------+-----+---------+----------------+
| id        | int(10) unsigned |      | PRI | NULL    | auto_increment |
| hostname  | varchar(32)      |      |     |         |                |
| volname   | varchar(32)      |      |     |         |                |
| qtreename | varchar(32)      |      |     |         |                |
| allocated | int(10) unsigned |      |     | 0       |                |
| used      | int(10) unsigned |      |     | 0       |                |
| available | int(10) unsigned |      |     | 0       |                |
| files     | int(10) unsigned | YES  |     | 0       |                |
| timestamp | datetime         | YES  | MUL | NULL    |                |
+-----------+------------------+------+-----+---------+----------------+
Thread
'GROUP BY' behaviorBill Adams28 Oct
  • Re: 'GROUP BY' behaviorSGreen28 Oct
RE: 'GROUP BY' behaviorBill Adams29 Oct
  • Re: 'GROUP BY' behaviorMichael Stassen31 Oct