From: | "Scott Marlowe" <scott(dot)marlowe(at)gmail(dot)com> |
---|---|
To: | delux256-postgresql(at)yahoo(dot)com |
Cc: | "PostgreSQL GENERAL List" <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: Group By question |
Date: | 2007-10-16 15:11:06 |
Message-ID: | dcc563d10710160811o35ff53d5x1ef27a5796dfe4d8@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On 10/16/07, Jeff Lanzarotta <delux256-postgresql(at)yahoo(dot)com> wrote:
> Hello,
>
> I have a table that looks something like this:
>
> SKU Dept Col1 Col2 Col3
> ------- ------ ------- ------- ------
> 1 1 1 2 3
> 2 1 2 3 4
> 3 2 1 0 1
> 4 2 0 1 2
> 5 2 4 1 3
> 6 3 1 2 3
>
> I am having a problem trying to get the Is there a query that can do
> something like this:
>
> select sku, dept, (col1 + col2) * col3) from table group by dept
So, what would the output look like?
For instance, you've got these two lines at the top:
SKU Dept Col1 Col2 Col3
------- ------ ------- ------- ------
1 1 1 2 3
2 1 2 3 4
If we group by dept, then how do I handle those two rows? Which SKU
would be the right one? Would the answer be
((sum(col1)+sum(col2))*sum(col3)) ??
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2007-10-16 15:16:46 | Re: improvement proposition |
Previous Message | Scott Marlowe | 2007-10-16 15:08:04 | Re: PostgreSQL as a backend for Wizcon 9.2 |