macability Posted September 13, 2003 Share Posted September 13, 2003 Hello, Can anybody help me with a SQL query problem which I have. I have 2 fields which I would like to add another 2 more fields with a calculation, one field calculates with a level return, the other is a 10% increase or decrease. For example the table will hold the following data Field_A : Field_B 1 : 1.4 2 : 1.7 1 : 1.3 5 : 1.0 3 : 1.0 I would like to only add field A if the result is 1 else I will want to subtract 1 . So I have an SQL statement which looks look like select Field_A, Field_B, SUM(IF(Field_A=1, Field_B.-1)) AS Field_C from mytable group by Field_A ; Field_A : Field_B: Field_C 1 : 1.4 : 1.4 2 : 1.7 : 0.4 1 : 1.3 : 1.7 5 : 1.0 : 0.7 3 : 1.0 : -0.3 What I would like to do for the next field (Field_D) is have it count up using a 10% increments for example: If Field_A=1 then I would like take a Field_B and multiply it by a 10% of the bank total. If Field_A does not equal 1 then decrease the bank by 10 % Field_D starts at 1 units Field_A : Field_B: Field_C: Field_D 1 : 1.4 : 1.4 : 1.14 2 : 1.7 : 0.4 : 1.03 1 : 1.3 : 1.7 : 1.16 5 : 1.0 : 0.7 : 1.04 3 : 1.0 : -0.3 : 0.94 Any advise people can give me will greatly be appreciated. regards Stevie D. Link to comment https://forums.phpfreaks.com/topic/1011-field-calculation-question/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.