pacome Posted June 8, 2007 Share Posted June 8, 2007 Hi! Let's say I've retrieved some data from a DB... I've got two different prices: $currentprice and $previousprice.. I would like to work out which have the highest increase in price from my list... I managed to work out porcentages by doing something like: $evolution = ($row[currentprice]-$row[previousprice])/$row[previousprice]*100; but I would like to select the top 10 highest increases for example... Can you do that? Thank you very much! Quote Link to comment https://forums.phpfreaks.com/topic/54796-solved-sql-query/ Share on other sites More sharing options...
chigley Posted June 8, 2007 Share Posted June 8, 2007 SELECT (currentprice - previousprice) AS difference FROM table ORDER BY difference ASC LIMIT 1 Completely untested, not that up on MySQL like this.. hope it works! Quote Link to comment https://forums.phpfreaks.com/topic/54796-solved-sql-query/#findComment-270972 Share on other sites More sharing options...
pacome Posted June 8, 2007 Author Share Posted June 8, 2007 right! I tried that... I don't know what the name of the new variable will be... I tried $difference it's ok!! great! do you know how to find out what are the name of the original variables that selected? The DB has the following: id, players, previousprice, currentprice and nickplayer... you see I need to show the name of the top 5 players that have increased it's price the highest... Thank you for your help! Quote Link to comment https://forums.phpfreaks.com/topic/54796-solved-sql-query/#findComment-271014 Share on other sites More sharing options...
pacome Posted June 8, 2007 Author Share Posted June 8, 2007 ok.. after a little testing I got the rest... I had to add the "players" to the query: SELECT players, (currentprice - previousprice) AS difference FROM table ORDER BY difference ASC LIMIT 1 then it was: $row['difference'] and $row['players']... thanks a lot Quote Link to comment https://forums.phpfreaks.com/topic/54796-solved-sql-query/#findComment-271036 Share on other sites More sharing options...
chigley Posted June 8, 2007 Share Posted June 8, 2007 No problem, glad it worked Quote Link to comment https://forums.phpfreaks.com/topic/54796-solved-sql-query/#findComment-271109 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.