suprsnipes Posted June 2, 2009 Share Posted June 2, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/160568-help-with-sql-query-previously-calculated-in-excel/ Share on other sites More sharing options...
Alt_F4 Posted June 2, 2009 Share Posted June 2, 2009 Look into stored procedures for the database that you are using. You can let the database look after the logic and do the work for you Quote Link to comment https://forums.phpfreaks.com/topic/160568-help-with-sql-query-previously-calculated-in-excel/#findComment-847432 Share on other sites More sharing options...
suprsnipes Posted June 2, 2009 Author Share Posted June 2, 2009 I'm using MySQL. A stored procedure sounds like a good idea but I need some help writing the query in the first place... Quote Link to comment https://forums.phpfreaks.com/topic/160568-help-with-sql-query-previously-calculated-in-excel/#findComment-847445 Share on other sites More sharing options...
Mark Baker Posted June 2, 2009 Share Posted June 2, 2009 Why not retain Excel for the business logic by using a PHP based calculation engine that replicates Excel functionality? Quote Link to comment https://forums.phpfreaks.com/topic/160568-help-with-sql-query-previously-calculated-in-excel/#findComment-847577 Share on other sites More sharing options...
suprsnipes Posted June 2, 2009 Author Share Posted June 2, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/160568-help-with-sql-query-previously-calculated-in-excel/#findComment-847578 Share on other sites More sharing options...
Mark Baker Posted June 3, 2009 Share Posted June 3, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/160568-help-with-sql-query-previously-calculated-in-excel/#findComment-848379 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.