General SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesGeneral SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old September 15th, 2003, 06:01 AM
MacAbility MacAbility is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 1 MacAbility User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
field calculation problem

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.

Reply With Quote
  #2  
Old September 22nd, 2003, 07:13 PM
md2perpe md2perpe is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 12 md2perpe User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Do you mean something accumulative?

On row 1, Field_C = Field_B.
On row n, if Field_A == 1, then Field_C = Field_A + (Field_C of row (n-1)), else Field_C = -1 + (Field_C of row (n-1));

Do you have to keep this in the database? Can't you just calculate it when fetching the data?

The values of Field_D I don't understand.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesGeneral SQL Development > field calculation problem


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT