X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id AA525DA1E0 for ; Wed, 5 Oct 2005 10:19:45 -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 40696-03 for ; Wed, 5 Oct 2005 13:19:37 +0000 (GMT) Received: from obelix.askesis.nl (laudanum.demon.nl [82.161.125.16]) by svr1.postgresql.org (Postfix) with ESMTP id 86324DA18C for ; Wed, 5 Oct 2005 10:19:37 -0300 (ADT) Received: obelix.askesis.nl 172.31.0.1 from 172.31.1.8 172.31.1.8 via HTTP with MS-WebStorage 6.0.6249 Received: from Panoramix by obelix.askesis.nl; 05 Oct 2005 15:19:41 +0200 Subject: Re: Help with simple SQL query? From: Joost Kraaijeveld To: Frank van Vugt Cc: "Pgsql-sql@postgresql.org" In-Reply-To: <200510051421.56840.ftm.van.vugt@foxi.nl> References: <71E37EF6B7DCC1499CEA0316A2568328024BBA0B@loki.wc.globexplorer.net> <200510051421.56840.ftm.van.vugt@foxi.nl> Content-Type: text/plain Content-Transfer-Encoding: 7bit Date: Wed, 05 Oct 2005 15:19:40 +0200 Message-Id: <1128518380.3655.226.camel@Panoramix> Mime-Version: 1.0 X-Mailer: Evolution 2.0.4 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.1 required=5 tests=[AWL=0.050, FORGED_RCVD_HELO=0.05] X-Spam-Level: X-Archive-Number: 200510/34 X-Sequence-Number: 22887 On Wed, 2005-10-05 at 14:21 +0200, Frank van Vugt wrote: > Hi Joost, > > Try joining and comparing the order table with/to an aggregated orderline > table, something like this: > > select order_id, order_price, sum_price, order_price - sum_price as diff > from order, (select parent_order_id, sum(orderline_price) as sum_price > from orderline group by parent_order_id) as foo > where order_id = parent_order_id > and order_price != sum_price > > > This should prove to be as efficient as it gets ;) How nice. An answer between the questions. And a working anser!. Which manual did I miss ;-) Thanks. -- Groeten, Joost Kraaijeveld Askesis B.V. Molukkenstraat 14 6524NB Nijmegen tel: 024-3888063 / 06-51855277 fax: 024-3608416 e-mail: J.Kraaijeveld@Askesis.nl web: www.askesis.nl