Jump to content

Recommended Posts

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

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.