Jump to content


Photo

Field calculation question


  • Please log in to reply
No replies to this topic

#1 macability

macability
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 13 September 2003 - 01:41 PM

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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users