Connecting Tech Pros Worldwide Help | Site Map
 
 
LinkBack Thread Tools Search this Thread
  #1  
Old March 28th, 2006, 08:15 AM
Michel de Becdelièvre
Guest
 
Posts: n/a
Default Computing the product of a column groupped by...

I need your help here :

I need to compute the product of a column, with conditions, over a
table, grouped by a key (it is a probability table).

In fact I need the exact equivalent of :

select key1, key2, sum( val )
from "sometable"
where "some parameterized condition"
group by key1, key2

*except* that I want the *multiplication* of all "val" instead of the sum.

I'd like the output to behave as much as a table column aggregative
function as possible, it is used in other queries.

In Oracle I'd solve this by using pipelined table functions, in DB2 I'm
lost, since table functions can only return the result of a select.

Can anyone help me ?

Am I stuck with using a procedure storing large results sets in a
temporary table with all the concurrency problems that this causes ?

Using DB2 for windows / UNIX 8.1.2.

Thanks in advance for any suggestion.






  #2  
Old March 28th, 2006, 10:35 AM
Tonkuma
Guest
 
Posts: n/a
Default Re: Computing the product of a column groupped by...

My two ideas.
1) EXP(SUM(LOG(val)))
But, this returns floating point number. So, exact value could not be
received.

2) Use recursive query. (and common table expression, if you want
combine with other data)

  #3  
Old March 28th, 2006, 01:25 PM
Michel de Becdelièvre
Guest
 
Posts: n/a
Default Re: Computing the product of a column groupped by...


"Tonkuma" <tonkuma@jp.ibm.com> a écrit dans le message de news:
1143541103.309444.151090@g10g2000cwb.googlegroups. com...[color=blue]
> My two ideas.
> 1) EXP(SUM(LOG(val)))
> But, this returns floating point number. So, exact value could not be
> received.[/color]

Stupid me, I should have thought of this.

I like this idea, I'll check if there is not too much imprecision in the
result, I think it should be OK. It's probabilities anyway.

thanks !


  #4  
Old April 3rd, 2006, 10:05 AM
Knut Stolze
Guest
 
Posts: n/a
Default Re: Computing the product of a column groupped by...

Tonkuma wrote:
[color=blue]
> My two ideas.
> 1) EXP(SUM(LOG(val)))
> But, this returns floating point number. So, exact value could not be
> received.
>
> 2) Use recursive query. (and common table expression, if you want
> combine with other data)[/color]

Another alternative is to roll your own aggregates. But this is not
trivial: http://tinyurl.com/7z49y and for groupings:
http://tinyurl.com/b2rq5

--
Knut Stolze
DB2 Information Integration Development
IBM Germany
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 205,414 network members.