Re: multiple paramters in aggregate function - Mailing list pgsql-general

From Sim Zacks
Subject Re: multiple paramters in aggregate function
Date
Msg-id 4A8D0200.5000807@compulab.co.il
Whole thread Raw
In response to Re: multiple paramters in aggregate function  (Sim Zacks <sim@compulab.co.il>)
List 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


pgsql-general by date:

Previous
From: Sim Zacks
Date:
Subject: Re: multiple paramters in aggregate function
Next
From: Kalai R
Date:
Subject: Field's position in Table