﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>Teradata Forums / Teradata  / Teradata Database  / Perform Multiplication of all the values for a Column / Latest Posts</title><generator>InstantForum.NET v4.1.4</generator><description>Teradata Forums</description><link>http://www.teradata.com/teradataforum/</link><webMaster>info@teradata.com</webMaster><lastBuildDate>Wed, 03 Dec 2008 16:25:18 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Perform Multiplication of all the values for a Column</title><link>http://www.teradata.com/teradataforum/Topic11624-9-1.aspx</link><description>A small change in the above query..select (-1**dt3.c3) * dt1.c1*dt2.c2 as product_col from((select COALESCE(exp(sum(ln(abs(a)))),1) from au.dh where a &amp;lt;0) dt1 (c1)join (select exp(sum(ln(a))) from au.dh where a &amp;gt; 0) dt2 (c2)on 1=1join(select count(a) from au.dh where a&amp;lt;0) dt3 (c3)on 1=1)</description><pubDate>Thu, 24 Jul 2008 02:10:19 GMT</pubDate><dc:creator>dhirajpalse</dc:creator></item><item><title>RE: Perform Multiplication of all the values for a Column</title><link>http://www.teradata.com/teradataforum/Topic11624-9-1.aspx</link><description>Hi,i created a table 'dh' in 'au' database with column name as 'A' of integer data type.Data in this column is as follows.A-10-9-612345I wrote the query, which is just an enhancement of Carlos's query.select (-1**dt3.c3) * dt1.c1*dt2.c2 as product_col from((select exp(sum(ln(abs(a)))) from au.dh where a &amp;lt;0) dt1 (c1)join (select exp(sum(ln(a))) from au.dh where a &amp;gt; 0) dt2 (c2)on 1=1join(select count(a) from au.dh where a&amp;lt;0) dt3 (c3)on 1=1)this gives the product of the column data by taking care of the signs of numbers.output with the given data is -64800.00hope this will help u.</description><pubDate>Thu, 29 May 2008 03:38:57 GMT</pubDate><dc:creator>dhirajpalse</dc:creator></item><item><title>RE: Perform Multiplication of all the values for a Column</title><link>http://www.teradata.com/teradataforum/Topic11624-9-1.aspx</link><description>Hi Carlos,Firstly thanks a lot for your reply.I also tried the same and it is working.sel  cast (EXP(SUM(LN(abs(dept_count)))) as decimal  ) *(case when ((-1 *sum(case when dept_count&amp;lt;0 then 1 else 0 end)) mod 2 )=0then 1else -1end)         as COL_PROD from dept;Table DeptDept_Name Dept_CountA                1B               -2 C               -3</description><pubDate>Thu, 29 May 2008 03:35:43 GMT</pubDate><dc:creator>Gaurav_Mishra</dc:creator></item><item><title>RE: Perform Multiplication of all the values for a Column</title><link>http://www.teradata.com/teradataforum/Topic11624-9-1.aspx</link><description>Hi again&amp;gt;&amp;gt;"Then product should have to be -20 but using log it won't work.&amp;gt;&amp;gt;Using ABS(absolute) will give you the product but will supress&amp;gt;&amp;gt;the sign in the Product value.&amp;gt;&amp;gt;Any suggestions on this?"Try: SELECT (case when sum(case when dept_count &amp;lt; 0 then 1 else 0 end) mod 2 = 1 then -1 else 1 end) * EXP(SUM(LN(ABS(dept_count)))) FROM dept_countHope this helps.Cheers.Carlos</description><pubDate>Thu, 29 May 2008 03:03:34 GMT</pubDate><dc:creator>CarlosAL</dc:creator></item><item><title>RE: Perform Multiplication of all the values for a Column</title><link>http://www.teradata.com/teradataforum/Topic11624-9-1.aspx</link><description>Hi Carlos,What if we need the sign also in the product?Say if the values are like 1-45Then product should have to be -20 but using log it won't work.Using ABS(absolute) will give you the product but will supress the sign  in the Product value.Any suggestions on this?</description><pubDate>Wed, 28 May 2008 22:29:56 GMT</pubDate><dc:creator>Gaurav_Mishra</dc:creator></item><item><title>RE: Perform Multiplication of all the values for a Column</title><link>http://www.teradata.com/teradataforum/Topic11624-9-1.aspx</link><description>hi carlos,just browsing thru the posts and your solution is an interesting way of using the available functions effectivily.....thats cool!</description><pubDate>Wed, 28 May 2008 11:26:44 GMT</pubDate><dc:creator>SN</dc:creator></item><item><title>RE: Perform Multiplication of all the values for a Column</title><link>http://www.teradata.com/teradataforum/Topic11624-9-1.aspx</link><description>Hi.This is my first answer to any post here (I'm quite new to Teradata, big DB background though).Recalling from my maths: 1. logarithm converts products in sums.2. logarithm and exponentiation are inverse functions.SoSELECT EXP(SUM(LN(dept_count))) from Dept_Count should give you the answer.Cheers.Carlos.</description><pubDate>Wed, 28 May 2008 06:33:35 GMT</pubDate><dc:creator>CarlosAL</dc:creator></item><item><title>Perform Multiplication of all the values for a Column</title><link>http://www.teradata.com/teradataforum/Topic11624-9-1.aspx</link><description>Dear All,Is their any way to perform the multiplication of all the values for a column using recursion.Regards,Gaurav.e.gTable Dept_CountDept_Name Dept_CountIT                 2Finance          3Treasurey       5CS                 1 The product of all the records for Dept_Count Col should have to be 30(2*3*5*1)</description><pubDate>Wed, 28 May 2008 01:50:02 GMT</pubDate><dc:creator>Gaurav_Mishra</dc:creator></item></channel></rss>