X-Original-To: pgsql-admin-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 5736BD8024 for ; Thu, 25 Aug 2005 10:20:24 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 74498-08 for ; Thu, 25 Aug 2005 13:20:22 +0000 (GMT) Received: from wolff.to (wolff.to [66.93.197.194]) by svr1.postgresql.org (Postfix) with SMTP id 48215D800F for ; Thu, 25 Aug 2005 10:20:20 -0300 (ADT) Received: (qmail 18277 invoked by uid 500); 25 Aug 2005 13:19:58 -0000 Date: Thu, 25 Aug 2005 08:19:58 -0500 From: Bruno Wolff III To: Richard Susanto Cc: pgsql-admin@postgresql.org, pgsql-sql@postgresql.org Subject: Re: How this query! Message-ID: <20050825131958.GD15100@wolff.to> Mail-Followup-To: pgsql-sql@postgresql.org, bruno@wolff.to, richard@orbisindonesia.com References: <62683.202.152.170.186.1124970240.squirrel@202.152.170.186> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <62683.202.152.170.186.1124970240.squirrel@202.152.170.186> User-Agent: Mutt/1.5.6i X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.006 required=5 tests=[AWL=0.006] X-Spam-Level: X-Archive-Number: 200508/313 X-Sequence-Number: 18632 On Thu, Aug 25, 2005 at 18:44:00 +0700, Richard Susanto 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 ;