> 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


-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

Reply via email to