Jump to content

Query a row of data against previous row of data in MySQL and return result


suprsnipes

Recommended Posts

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

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]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.