1. select city, sum(price) from table_name group by city i thing sum will only add all price value and not get the average of it better work with avg aggregate function *select city, avg(price) from table_name group by city* 2. select city, count(price) from table_name group by city here it will not handle the descending logic which is ask for *select city, count(price) as res from table_name group by city order by res desc* On 12/13/07, Muthukumar Selvarasu <muthukumar_se@xxxxxxxxxxx> wrote: > > > > Hi > > here solution for your problem > > CREATE TABLE `table_name` ( > > `id` int(11) NOT NULL auto_increment, > > `city` varchar(255) default NULL, > > `price` float default NULL, > > PRIMARY KEY (`id`) > > ) > > insert into `table_name` (`id`,`city`,`price`) values (1,'sydney',10); > > insert into `table_name` (`id`,`city`,`price`) values (2,'melbourne',20); > > insert into `table_name` (`id`,`city`,`price`) values (3,'sydney',30); > > insert into `table_name` (`id`,`city`,`price`) values (4,'melbourne',10); > > insert into `table_name` (`id`,`city`,`price`) values (5,'sydney',20); > > insert into `table_name` (`id`,`city`,`price`) values (6,'melbourne',30); > > insert into `table_name` (`id`,`city`,`price`) values (7,'sydney',39); > > insert into `table_name` (`id`,`city`,`price`) values (8,'melbourne',449); > > insert into `table_name` (`id`,`city`,`price`) values (9,'melbourne',22); > > insert into `table_name` (`id`,`city`,`price`) values > (10,'melbourne',111); > > Answer > > 1. select city, sum(price) from table_name group by city > > 2. select city, count(price) from table_name group by city > > Thanks, > > Muthukumar Selvarasu, > > Project Manager (Web Development), > > Webmasters Ltd. > > _____ > > From: php-objects@xxxxxxxxxxxxxxx <php-objects%40yahoogroups.com> [mailto: > php-objects@xxxxxxxxxxxxxxx <php-objects%40yahoogroups.com>] On > Behalf Of Sudhakar > Sent: Thursday, December 13, 2007 12:12 AM > To: php-objects@xxxxxxxxxxxxxxx <php-objects%40yahoogroups.com> > Subject: VERY URGENT question about calculating average > > presently there is a table which records information about users > enquiring for fares to a particular destination. > > in the existing report which is a php file when a particular date is > selected this php file will display the total number of enquiries for > each destination and its price for a particular dates. in this php > file a select query is executed along with GROUP BY and ORDER BY > > ex= > DESTINATION PRICE > sydney 1000 > melbourne 2500 > perth 2000 > sydney 2000 > sydney 3000 > > my question is > > 1. > i would like to add all sydney fares and find the average and > similarly for other cities. ex= > > DESTINATION PRICE > sydney 500 > melbourne 200 > > 2. > i would like to display the city which had the maximum number of > enquiries to the city with minimum enquiries in a descending order > with the numeric value. > > please provide the code for 1 and 2. > > thanks in advance. > > [Non-text portions of this message have been removed] > > > -- Thanks & Regards, [Non-text portions of this message have been removed]