Hi, Is there any way to let SQL aware of a temporary variable which value varies from record to record? The job needs to be done is following:
Suppose C1 and C2 are two columns in the table, a1 and a2 are two constants. f1(x) to fn(x) is n transformation functions. want to get: select sum(f1(C1*a1+C2*a2)), sum(f2(C1*a1+C2*a2)), ... sum(fn(C1*a1+C2*a2))
Is there any way that SQL can first remember a variable y=C1*a1+C2*a2 for each record, then directly use this y to do the select: sum(f1(y)), sum(f2(y)), ... sum(fn(y))
I know one way to do this is by a temporary table. But does Teradata has such build-in functionality to calculate y first, then do the aggregation on the fly?
Not sure if this is what you are looking for, but you could create a view and define y as C1*a1+C2*a2 and then just reference your view in the select. If you are looking to keep changing y then you just change your view to the new formula.