suprsnipes Posted May 27, 2009 Share Posted May 27, 2009 Hi, I've only learned about MySQL and PHP this week and have a basic grasp of running an SQL query after reading some tutorials. I have data in a MySQL database and I want to classify each row of data based on meeting certain criteria and to do this I need to be able to refer to the previous rows data. How would I go about doing this? Thank you in advance, suprsnipes Link to comment https://forums.phpfreaks.com/topic/159805-query-a-row-of-data-against-previous-row-of-data-in-mysql-and-return-result/ Share on other sites More sharing options...
suprsnipes Posted May 27, 2009 Author Share Posted May 27, 2009 I have placed an attachment asking for a little help with putting this query together. ID is assigned auto-increment, the other columns are Type, Price and Size. Please forgive my explanation but I was previously calculating this in Excel and need to move to MySQL database. I want to do the following; If Type = 'S' I want to compare it to the previous rows data and insert a new column in the existing database, let's call the new column 'nc'; If the previous rows type = b & the price of the current column is equal to or below then insert in 'nc' the word 'sell' If the previous rows type = b & the price of the current column is above then insert in 'nc' the word 'buy' If the previous rows type = a & the price of the current column is equal to or above then insert in 'nc' the word 'buy' If the previous rows type = a & the price of the current column is below then insert in 'nc' the word 'sell' Once I get a kick start I'll be ok. I really appreciate the help. [attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/159805-query-a-row-of-data-against-previous-row-of-data-in-mysql-and-return-result/#findComment-842933 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.