From: | Sim Zacks <sim(at)compulab(dot)co(dot)il> |
---|---|
To: | Alban Hertroys <dalroi(at)solfertje(dot)student(dot)utwente(dot)nl> |
Cc: | Scara Maccai <m_lists(at)yahoo(dot)it>, pgsql-general(at)postgresql(dot)org |
Subject: | Re: multiple paramters in aggregate function |
Date: | 2009-08-20 07:57:52 |
Message-ID: | 4A8D0200.5000807@compulab.co.il |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
> My query contains select ..,
> sum_unitvalues(qty,unitid),sum_units(unitid),...
> then the units returned do not have to be known in advance, which is
> important in this specific project.
>
To give an example of my required result set:
unitid
1 = mm
2 = inch
3 = ft
4 = gram
create table test(id serial primary key, qty numeric(12,4), unitid int);
insert into test(qty,unitid)
values(100,2),(200,2),(5,3),(20,1),(800,4)
select sum_unitvalues(qty,unitid) as qty, sum_units(unitid) as unitid
from test where unitid<>4;
qty | unitid
----------------------------
9124 | 1
select sum_unitvalues(qty,unitid) as qty, sum_units(unitid) as unitid
from test where unitid not in (1,4);
qty | unitid
----------------------------
360 | 2
select sum_unitvalues(qty,unitid) as qty, sum_units(unitid) as unitid
from test;
qty | unitid
----------------------------
NULL | NULL
From | Date | Subject | |
---|---|---|---|
Next Message | Kalai R | 2009-08-20 09:05:52 | Field's position in Table |
Previous Message | Sim Zacks | 2009-08-20 07:36:37 | Re: multiple paramters in aggregate function |