From: Bruno Wolff III <bruno@wolff.to>
To: Richard Susanto <richard@orbisindonesia.com>
Cc: pgsql-admin@postgresql.org
Cc: pgsql-sql@postgresql.org
Subject: Re: How this query!
Date: Thu, 25 Aug 2005 08:19:58 -0500
Message-ID: <20050825131958.GD15100@wolff.to> (raw)
In-Reply-To: <62683.202.152.170.186.1124970240.squirrel@202.152.170.186>
References: <62683.202.152.170.186.1124970240.squirrel@202.152.170.186>
On Thu, Aug 25, 2005 at 18:44:00 +0700,
Richard Susanto <richard@orbisindonesia.com> wrote:
> Folks,
> would you like help me how to query this case.
This question is off topic for the pgsql-admin list, it should have been
asked on the pgsql-sql list because it was a question about SQL. (I probably
wouldn't have said anything if it had been posted to the pgsql-general
or pgsql-novice lists, but it is definitely not a question even remotely
related to postgres administration.)
>
> I have tbl_a, the fields are :
> item_record
> item_product_name
> item_qty
>
>
> if the data are :
>
> item_record = 1,2,3,4,5,6
> item_product_name = a,b,a,c,d,c,...
> item_qty = 10,5,15,10,20,5,...
>
> How the query to sum item_qty_total if i want the result :
> item_product_name = a,b,c,d
> item_qty_total = 25,5,15,20
Use GROUP BY item_product_name and sum(item_qty). Something like:
SELECT item_product_name, sum(item_qty) AS item_qty_total
FROM tbl_a
GROUP BY item_product_name
ORDER BY item_product_name
;
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: bruno@wolff.to, richard@orbisindonesia.com, pgsql-admin@postgresql.org
Subject: Re: How this query!
In-Reply-To: <20050825131958.GD15100@wolff.to>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox