Click to See Complete Forum and Search --> : Displaying the average the price and the increase


rjoseph
11-04-2007, 01:12 PM
Hi Guys

A friend kindly helped me find a soltuion which allowed me to display the average value of a numerical "price" field in my database onto my page.

However, the next stage is based on a further calculation. I now need to use the "average" figure that I have displayed on my page and set it against the "Price" figure to get the % increase.

For example,

------------record displayed on page-----------
Make: Porsche
Price: 45999.99

AvePrice of all Porsche 911's: 42999.45
Increase: 6.95%
------------------------------------------------

Has anyone got any ideas how I would display the % Increase within my results like shown above? The Ql statement I am currently using look as follows:

------------SQL------------
sqlStrB = "SELECT (CAST(SUM(PRICE) AS FLOAT) / COUNT(*)) AS [AvePrice] FROM mytable"
sqlStrB = sqlStrB & " where make = 'Porche'"
---------------------------

Any help would be fully appreciated.

Best regards

Rod from the UK

Zoidal
11-06-2007, 01:29 PM
You may find some help here, use avg for your select statement:
http://www.sql-tutorial.com/sql-aggregate-functions-sql-tutorial/

As for the rest, I prefer to use a database program and create tables and queries within the program to do the calculations and just display what I need via whatever variable requested by user, especially if the choices are rather finite.