Download presentation
Presentation is loading. Please wait.
1
Calculating Product of Values in Same Column
Farrokh Alemi, Ph.D. In this section we discuss how the course on databases is related to additional courses in the program. This brief presentation was organized by Alemi and narrated by xxx.
2
Easy & Hard Way If we want to calculate the product of values in different columns, it is easy to do. We have a function that does it for us. For example, the product of 2 and 4 in two different columns can be easily calculated. This SQL command puts the product of 2 times 4 in Column 3.
3
Easy & Hard Way , [Column 1] * [Column 2] AS [Column 3]
This SQL command puts the product of 2 times 4 in Column 3. The star between the two column names is an internal math function that calculates the product of the two columns. This is easy to do. We do not need to make the function.
4
Easy & Hard Way When all values are in the same column, this is a lot harder to do. In many query languages, there is no simple internal function that can calculate the product of values in the same column. There is no math function that will be able to multiply 2 and 4 and get us to 8. All we know how to do with data in one column is use the sum function to add the values together. In this video we show you how to use the sym function to calculate a product of values in the same column of data.
5
log(x) + Log(y) = Log(xy)
Easy & Hard Way log(x) + Log(y) = Log(xy) We use a well known relationship that the sum of log of values is the log of product of the values. We transform the data to logs, calculate the sum of logs, this produces the log of the product. We now transfer back to the initial scale and report the product.
6
Logarithm Function Let us start with understanding the logarithm function. Here the x axis or the horizontal axis shows the value of x, the values in the column of data. The Y axis shows the logirthm of x. The graph of the logarithm to natural base crosses the horizontal axis at 1.
7
Logarithm Function It passes through the points with coordinates of 2 and 0.69.
8
Logarithm Function Also the point with coordinates 4 and 1.39.
9
Logarithm Function And 8 and 2.08 because e to power of 2.08 is 8, where e is the natural number of
10
Logarithm Function The graph never crosses the y axis but does get close to it as x values get closer to 0.
11
log([Column 1]) 0.69 Suppose the values in column 1 are 2 and 4. We want to calculate the product of these values. The first step is to take the log of these values for 2 it is 0.69.
12
log([Column 1]) 1.39 0.69 For 4 it is 1.39.
13
Sum(log([Column 1])) 2.08 1.39 0.69 We now sum the calculated log values. Which gives us the value of 2.08.
14
Exp(Sum(log([Column 1])))
2.08 1.39 0.69 In the last step we take antilog or in other words we take e to the power of 2.08, which gives us the X value of 8.
15
Exp(Sum(log([Column 1])))
0.69 1.39 2.08 So we see that taking the exponential of sum of the log of the values in the column produces the product of the value. In this case, it multiplied 2 by 4 and gave us the resulting 8.
16
Exception: Log of zero is not defined
Exp(Sum(iif([Column 1]=0, 0,log([Column 1]))) Exception: Log of zero is not defined There are two exceptions to this method. First, log of zero is not defined so we have to calculate situations where there is a 0 in the column using a different method. We know when the column contains a zero the product of the values in the column is zero. So we insert that with an if statement into the code.
17
Exception: Calculated number cannot exceed largest allowed
Exp(IIF(Sum(iif([Column 1]=0, 0,log([Column 1]))>100, 100, Sum(iif([Column 1]=0, 0,log([Column 1]))) Exception: Calculated number cannot exceed largest allowed The second exceptions occurs when the sum of the log of the numbers is so large that e to its power exceeds the largest number allowed in the computer. Here again we need to insert an if statement that controls for very large numbers. In this case, we are saying if the sum of the log of the column values exceeds 100 then assume it is 100; otherwise enter the sum as calculated. In this manner the sum never exceeds e to the power of 100
18
Product of values in a column
This video has shown how to code the data to calculate the product of the values within one column of data.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.