Example: Calculating the Fraction of Cost

Teradata Vantage™ SQL Functions, Expressions, and Predicates

brand
Software
Teradata Vantage
prodname
Teradata Database
Teradata Vantage NewSQL Engine
vrm_release
16.20
category
Programming Reference
featnum
B035-1145-162K

The following example uses a Valued CASE expression to calculate the fraction of cost in the total cost of inventory represented by parts of type ‘1’:

   SELECT SUM(CASE part
               WHEN '1' 
               THEN cost
               ELSE 0
              END
             )/SUM(cost)
   FROM t;