Article View: comp.databases.ms-access
Article #129Re: SQL GROUP BY problem
From: MarkC
Date: Wed, 10 May 2000 00:00
Date: Wed, 10 May 2000 00:00
48 lines
2200 bytes
2200 bytes
use the sum function to total the price by inv_id. <ammar_aganovic@my-deja.com> wrote in message news:8fbq8o$2g1$1@nnrp1.deja.com... > This is a simplified version of my problem (in reality I need the GROUP > BY orders.id to calculate a price) > > select > orders.inv_id, > products.price > from orders > LEFT JOIN products ON products.id = orders.prod_id > GROUP BY orders.id, inv_id > > returns: > > > inv_id | price > --------------------------------------------------------- > 1 | 13 > 1 | 50 > 2 | . > 2 | . > 2 | . > . | . > > > And this is what I would like to get: > > inv_id | total > -------------- > 1 | 63 > 2 | . > . | . > . | . > > > I need to group the result table by inv_id and sum the sum column - I > thought it would be simple, but I can't seem to get it working. I tried > modifying a GROUP BY line to "GROUP BY orders.id, orders.inv_id" (need > to order by orders.id to calculate a subtotal, and orders.inv_id to > calculate the total) but the rows wouldn't group :( Why?! How can I > perform a GROUP BY ona grouped rows? Documentation? > The DB is MySQL but this bight be a ANSI question. > > > Sent via Deja.com http://www.deja.com/ > Before you buy.
Technical Details
Message-ID:
<8fbr43$lcv$1@lure.pipex.net>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<8fbq8o$2g1$1@nnrp1.deja.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 115df1,ac960ef33eb4457 X-Google-Attributes: gid115df1,public X-Google-Thread: ff75c,ac960ef33eb4457 X-Google-Attributes: gidff75c,public X-Google-Thread: ff0ac,ac960ef33eb4457 X-Google-Attributes: gidff0ac,public From: "MarkC" <markc@lynxfs.com> Subject: Re: SQL GROUP BY problem Date: 2000/05/10 Message-ID: <8fbr43$lcv$1@lure.pipex.net> X-Deja-AN: 621576033 References: <8fbq8o$2g1$1@nnrp1.deja.com> X-Priority: 3 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2314.1300 X-Complaints-To: abuse@uk.uu.net X-Trace: lure.pipex.net 957968323 21919 62.188.162.92 (10 May 2000 14:18:43 GMT) Organization: UUNET WorldCom server (post doesn't reflect views of UUNET WorldCom X-MSMail-Priority: Normal NNTP-Posting-Date: 10 May 2000 14:18:43 GMT Newsgroups: comp.databases.ms-access,borland.public.delphi.database.desktop,microsoft.public.sqlserver.odbc