Article View: comp.databases.ms-access
Article #128SQL GROUP BY problem
From: ammar_aganovic
Date: Wed, 10 May 2000 00:00
Date: Wed, 10 May 2000 00:00
44 lines
1897 bytes
1897 bytes
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:
<8fbq8o$2g1$1@nnrp1.deja.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 115df1,ac960ef33eb4457,start X-Google-Attributes: gid115df1,public X-Google-Thread: ff75c,ac960ef33eb4457,start X-Google-Attributes: gidff75c,public X-Google-Thread: ff0ac,ac960ef33eb4457,start X-Google-Attributes: gidff0ac,public From: ammar_aganovic@my-deja.com Subject: SQL GROUP BY problem Date: 2000/05/10 Message-ID: <8fbq8o$2g1$1@nnrp1.deja.com> X-Deja-AN: 621564216 X-Http-Proxy: 1.1 x33.deja.com:80 (Squid/1.1.22) for client 143.50.30.94 Organization: Deja.com - Before you buy. X-Article-Creation-Date: Wed May 10 14:04:21 2000 GMT X-MyDeja-Info: XMYDJUIDammar_aganovic Newsgroups: comp.databases.ms-access,borland.public.delphi.database.desktop,microsoft.public.sqlserver.odbc X-Http-User-Agent: Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)