Jump to content

Help with SQL query - Previously calculated in Excel


suprsnipes

Recommended Posts

Help with SQL query

I have a table with the following columns.

 

ID1

TYPE1

PRICE1

SIZE1

 

I need to put together a query that calculates the following in the one step...previously I was calculating this in Excel.

 

1. IF(AND(TYPE1='N', PREVIOUS_ID1='a', PRICE1>=PREVIOUS_PRICE1),THEN

INSERT INTO new column SUM(+SIZE1)

 

2. IF(AND(TYPE1='N', PREVIOUS_ID1='b', PRICE1<=PREVIOUS_PRICE1),THEN INSERT INTO new column SUM(-SIZE1)

 

The SIZE1 column is shown as a number, for example 002, 011, 001 etc. If the above 1. statement is true then insert into new column the sum of size1 as a plus, if 2. statement is true insert into new column the sum of size1 as a negative for further analysis.

Link to comment
Share on other sites

Why not retain Excel for the business logic by using a PHP based calculation engine that replicates Excel functionality?

 

In saying that do you have any suggestions as to how I could go about this?

A little PHPExcel library listed in my signature would be one option. You can read/write Excel files directly from PHP, and it has a built-in calculation engine that replicates most of Excel's functions.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.