pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedHow this query!
3+ messages / 3 participants
[nested] [flat]
* How this query!
@ 2005-08-25 11:44 Richard Susanto <richard@orbisindonesia.com>
0 siblings, 2 replies; 3+ messages in thread
From: Richard Susanto @ 2005-08-25 11:44 UTC (permalink / raw)
To: pgsql-admin@postgresql.org
Folks,
would you like help me how to query this case.
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
Regards,
--
>>Richard Sitompul<<
Software Engineer
PT. Orbis Indonesia
http://www.orbisindonesia.com
http://richardsstp.3wsi.net
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: How this query!
@ 2005-08-25 12:21 Lars Haugseth <pgsql@larshaugseth.com>
parent: Richard Susanto <richard@orbisindonesia.com>
1 sibling, 0 replies; 3+ messages in thread
From: Lars Haugseth @ 2005-08-25 12:21 UTC (permalink / raw)
To: pgsql-admin@postgresql.org; +Cc: richard@orbisindonesia.com
* richard@orbisindonesia.com ("Richard Susanto") wrote:
|
| Folks,
| would you like help me how to query this case.
|
| 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
SELECT item_product_name, sum(item_qty) FROM tbl_a GROUP BY item_product_name;
--
Lars Haugseth
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: How this query!
@ 2005-08-25 13:19 Bruno Wolff III <bruno@wolff.to>
parent: Richard Susanto <richard@orbisindonesia.com>
1 sibling, 0 replies; 3+ messages in thread
From: Bruno Wolff III @ 2005-08-25 13:19 UTC (permalink / raw)
To: Richard Susanto <richard@orbisindonesia.com>; +Cc: pgsql-admin@postgresql.org; pgsql-sql
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
;
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2005-08-25 13:19 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-08-25 11:44 How this query! Richard Susanto <richard@orbisindonesia.com>
2005-08-25 12:21 ` Lars Haugseth <pgsql@larshaugseth.com>
2005-08-25 13:19 ` Bruno Wolff III <bruno@wolff.to>
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