Hey there I am not too familiar with advanced queries but I have a query like this:
$sql_ids = "
SELECT id, AVG(price) AS price, SUM(number_sales) AS number_sales
FROM table
WHERE year_of_sale >= 2000
GROUP BY id";
Well what I am trying to do is get the % change in price for each id from the beginning year (2000) to the present (2005). I need to use the query above, as you can see AVG is alright but how would I get % change of avg?
If I have 3 instances of id between 2000 and 2005 and a beginning price of $50 and an end price of $100 the % change according to the $ change equation:
((ending price)-(beginning price)) /(beginning price) * 100
that means a % change in price of 100%.
How can I compute something like that in my sql query? if that isnt possible what would be an alternative way to perform the query above given that there may be tens of thousands of records to search through??? Any ideas? Thanks!