fid
fid

Reputation: 72

Multiply values of same column with same id

There is a table like this:

ID Value
1 0.2
2 0.55
1 0.4
3 0.6
1 0.4
... ...

I want to multiply Values where I have the same ID.

So that I get a table looking like this:

ID Value
1 0.032
2 0.55
1 0.032
3 0.6
1 0.032
... ...

Unfortunately I have no point where to start for this that makes sense...

Upvotes: 1

Views: 300

Answers (2)

DannySlor
DannySlor

Reputation: 4620

There's a trick to doing that using exp, sum, and log.

select ID,  exp(sum(log(Value))) as Value
from t
group by ID
ID Value
1 0.08
2 0.55
3 0.6

Fiddle

Upvotes: 3

learning
learning

Reputation: 610

Try this

SELECT id, (a.value * b.value) as sum
FROM tablename, tablename a
WHERE tablename.id = a.id

Upvotes: 0

Related Questions