Search Postgresql Archives

Re: multiple paramters in aggregate function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> 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@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux