From: Ragnar <gnari@hive.is>
To: A. R. Van Hook <hook@lake-lotawana.mo.us>
Cc: postgresql sql list <pgsql-sql@postgresql.org>
Subject: Re: join problem
Date: Thu, 21 Jun 2007 18:43:00 +0000
Message-ID: <1182451380.5953.232.camel@localhost.localdomain> (raw)
In-Reply-To: <467A8142.1050508@lake-lotawana.mo.us>
References: <467A8142.1050508@lake-lotawana.mo.us>
On fim, 2007-06-21 at 08:46 -0500, A. R. Van Hook wrote:
> if I query for the total deposit using
> select sum(deposit)
> from invoice
> where cusid = 2128"
>
> I also get 1179.24, also the correct amount
>
>
> If I try an inclusive query using the following:
> select
> sum(i.rowtot + i.tax) as tot,
> sum(v.deposit) as deposit
> from cai c
> join invoice v on (v.cusid = c.cusid)
> left join invoiceitems i on (v.ivid = i.ivid)
> where v.cusid = 2128
> group by
> c.cusid
> I get
> tot | deposit
> ----------+---------
> 1179.240 | 2819.24
you are adding the invoice deposit once for each item
gnari
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: gnari@hive.is, hook@lake-lotawana.mo.us
Subject: Re: join problem
In-Reply-To: <1182451380.5953.232.camel@localhost.localdomain>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
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