Link to home
Start Free TrialLog in
Avatar of TECHADVICE
TECHADVICE

asked on

Multiply two variables then divide by third variable in same table

Given the following Table
ID  PERIOD     DATA1  DATA2   DATA3
A  20071001    32           4             23
B  20071001    22          10            5
C  20071001    46          12            15

How can I run a select statement that would
DATA1*DATA2 = DATA4
DATA4/DATA3 = DATA5
All in the same select statement

Desired results would be:
ID  PERIOD      DATA4    DATA5
A  20071001     128        5.57
B  20071001      220      44.00
C  20071001      552      36.80

Also, I would need the statement to account for divide by zero issues.
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

select id, period, data1*data2 as data4, (data1*data2) / data3 as data5
from yourtable
Avatar of TECHADVICE
TECHADVICE

ASKER

is it possible to amend similar to the following:
select id, period, data1*data2 as data4, data4/data3 as data5
from yourtable
SOLUTION
Avatar of ExistenceExists
ExistenceExists

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial