Re: mysq query without subselects

From: Date: Fri, 10 Sep 2004 17:55:40 +0000
Subject: Re: mysq query without subselects
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-36153@lists.php.net to get a copy of this message
From: "blackwater dev" <blackwaterdev@gmail.com>
I need to grab the max value of all of the data in a table grabbing the max total for each client. Example. T1
id        total      clientid
1          100           111
2          200           111
3          100           112
4          150           112
I need a query that will grab the highest total per clientid (200, and 150) then average them. My first inclination is to do a subselect select avg(total) from t1 where t1.total=(select max(total) from t1 t2 where t2.clientid=t1.clientid)
CREATE TEMPORARY TABLE tmp SELECT MAX(total) AS total FROM T1 GROUP BY clientid; SELECT AVG(total) FROM tmp;
But can't use subselects with mysql....how do I do it??
Sure you can... with the right version. ---John Holmes...

« previous php.db (#36153) next »